2 * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 3 of the GNU Lesser General Public License
6 * or later as published by the Free Software Foundation.
10 package eu.svjatoslav.sixth.e3d.geometry;
12 import static java.lang.Math.sqrt;
14 public class Point2D implements Cloneable {
21 public Point2D(final double x, final double y) {
26 public Point2D(final Point2D source) {
31 public Point2D add(final Point2D direction) {
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 source) {
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() {
86 public Point2D subtract(final Point2D point) {
92 public Point3D to3D() {
93 return new Point3D(x, y, 0);
96 public Point2D zero() {