2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
8 package eu.svjatoslav.sixth.e3d.geometry;
10 import static java.lang.Math.sqrt;
12 public class Point2D implements Cloneable {
19 public Point2D(final double x, final double y) {
24 public Point2D(final Point2D source) {
29 public Point2D add(final Point2D direction) {
35 public boolean isZero() {
36 return (x == 0) && (y == 0);
40 public Point2D clone() {
41 return new Point2D(this);
44 public void clone(final Point2D source) {
49 public Point2D getMiddle(final Point2D p1, final Point2D p2) {
50 x = (p1.x + p2.x) / 2d;
51 y = (p1.y + p2.y) / 2d;
55 public double getAngleXY(final Point2D anotherPoint) {
56 return Math.atan2(x - anotherPoint.x, y - anotherPoint.y);
60 * Compute distance to another point.
62 public double getDistanceTo(final Point2D anotherPoint) {
63 final double xDiff = x - anotherPoint.x;
64 final double yDiff = y - anotherPoint.y;
66 return sqrt(((xDiff * xDiff) + (yDiff * yDiff)));
69 public double getVectorLength() {
70 return sqrt(((x * x) + (y * y)));
73 public Point2D invert() {
79 public void roundToInteger() {
84 public Point2D subtract(final Point2D point) {
90 public Point3D to3D() {
91 return new Point3D(x, y, 0);
94 public Point2D zero() {
101 public String toString() {