2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.sixth.e3d.geometry;
7 import static java.lang.Math.sqrt;
9 public class Point2D implements Cloneable {
16 public Point2D(final double x, final double y) {
21 public Point2D(final Point2D parent) {
27 * Add other point to current point.
29 * @return current point.
31 public Point2D add(final Point2D otherPoint) {
37 public boolean isZero() {
38 return (x == 0) && (y == 0);
42 public Point2D clone() {
43 return new Point2D(this);
46 public void clone(final Point2D parent) {
51 public Point2D getMiddle(final Point2D p1, final Point2D p2) {
52 x = (p1.x + p2.x) / 2d;
53 y = (p1.y + p2.y) / 2d;
57 public double getAngleXY(final Point2D anotherPoint) {
58 return Math.atan2(x - anotherPoint.x, y - anotherPoint.y);
62 * Compute distance to another point.
64 public double getDistanceTo(final Point2D anotherPoint) {
65 final double xDiff = x - anotherPoint.x;
66 final double yDiff = y - anotherPoint.y;
68 return sqrt(((xDiff * xDiff) + (yDiff * yDiff)));
71 public double getVectorLength() {
72 return sqrt(((x * x) + (y * y)));
75 public Point2D invert() {
81 public void roundToInteger() {
87 * Subtract other point from current point.
89 * @return current point.
91 public Point2D subtract(final Point2D otherPoint) {
97 public Point3D to3D() {
98 return new Point3D(x, y, 0);
101 public Point2D zero() {
108 public String toString() {