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 source) {
26 public Point2D add(final Point2D direction) {
32 public boolean isZero() {
33 return (x == 0) && (y == 0);
37 public Point2D clone() {
38 return new Point2D(this);
41 public void clone(final Point2D source) {
46 public Point2D getMiddle(final Point2D p1, final Point2D p2) {
47 x = (p1.x + p2.x) / 2d;
48 y = (p1.y + p2.y) / 2d;
52 public double getAngleXY(final Point2D anotherPoint) {
53 return Math.atan2(x - anotherPoint.x, y - anotherPoint.y);
57 * Compute distance to another point.
59 public double getDistanceTo(final Point2D anotherPoint) {
60 final double xDiff = x - anotherPoint.x;
61 final double yDiff = y - anotherPoint.y;
63 return sqrt(((xDiff * xDiff) + (yDiff * yDiff)));
66 public double getVectorLength() {
67 return sqrt(((x * x) + (y * y)));
70 public Point2D invert() {
76 public void roundToInteger() {
81 public Point2D subtract(final Point2D point) {
87 public Point3D to3D() {
88 return new Point3D(x, y, 0);
91 public Point2D zero() {
98 public String toString() {