X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Fgeometry%2FPoint3D.java;h=295c10a512713dbc82ac5ca17091e336b4df3a5e;hb=197ac1b87328bb5b06ba52d3768af04b2007b087;hp=0b28de2559a4269475bb1afa6df70533e7afc23c;hpb=dcdff57f0bab42387b2e4e215778d9e8efc60221;p=sixth-3d.git diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java index 0b28de2..295c10a 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java @@ -1,22 +1,21 @@ /* - * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 3 of the GNU Lesser General Public License - * or later as published by the Free Software Foundation. + * Sixth 3D engine. Author: Svjatoslav Agejenko. + * This project is released under Creative Commons Zero (CC0) license. * +* */ package eu.svjatoslav.sixth.e3d.geometry; +import static java.lang.Math.*; + /** - * Used to represent point in a 3D space, vector or speed. + * Used to represent point in a 3D space or vector. */ -public class Point3D extends Point2D implements Cloneable { +public class Point3D implements Cloneable { - public static final Point3D ZERO = new Point3D(); - public double z; + public double x, y, z; public Point3D() { } @@ -46,12 +45,12 @@ public class Point3D extends Point2D implements Cloneable { } public Point3D add(final Point3D direction) { - super.add(direction); + x += direction.x; + y += direction.y; z += direction.z; return this; } - @Override public Point3D clone() { return new Point3D(this); } @@ -70,6 +69,10 @@ public class Point3D extends Point2D implements Cloneable { return this; } + public boolean isZero() { + return (x == 0) && (y == 0) && (z == 0); + } + public double getAngleXZ(final Point3D anotherPoint) { return Math.atan2(x - anotherPoint.x, z - anotherPoint.z); } @@ -78,6 +81,10 @@ public class Point3D extends Point2D implements Cloneable { return Math.atan2(y - anotherPoint.y, z - anotherPoint.z); } + public double getAngleXY(final Point3D anotherPoint) { + return Math.atan2(x - anotherPoint.x, y - anotherPoint.y); + } + /** * Compute distance to another point. */ @@ -86,11 +93,13 @@ public class Point3D extends Point2D implements Cloneable { final double yDelta = y - anotherPoint.y; final double zDelta = z - anotherPoint.z; - return Math - .sqrt(((xDelta * xDelta) + (yDelta * yDelta) + (zDelta * zDelta))); + return sqrt(((xDelta * xDelta) + (yDelta * yDelta) + (zDelta * zDelta))); + } + + public double getVectorLength() { + return sqrt(((x * x) + (y * y) + (z * z))); } - @Override public Point3D invert() { x = -x; y = -y; @@ -100,11 +109,11 @@ public class Point3D extends Point2D implements Cloneable { public void rotate(final Point3D center, final double angleXZ, final double angleYZ) { - final double s1 = Math.sin(angleXZ); - final double c1 = Math.cos(angleXZ); + final double s1 = sin(angleXZ); + final double c1 = cos(angleXZ); - final double s2 = Math.sin(angleYZ); - final double c2 = Math.cos(angleYZ); + final double s2 = sin(angleYZ); + final double c2 = cos(angleYZ); x -= center.x; y -= center.y; @@ -121,7 +130,6 @@ public class Point3D extends Point2D implements Cloneable { z = z2 + center.z; } - @Override public void roundToInteger() { x = (int) x; y = (int) y; @@ -149,7 +157,8 @@ public class Point3D extends Point2D implements Cloneable { } public Point3D subtract(final Point3D direction) { - super.subtract(direction); + x -= direction.x; + y -= direction.y; z -= direction.z; return this; } @@ -174,7 +183,7 @@ public class Point3D extends Point2D implements Cloneable { return this; } - public boolean withinDrawingLimits() { + public boolean isVisible() { if (z > 0) return true; @@ -186,9 +195,9 @@ public class Point3D extends Point2D implements Cloneable { return false; } - @Override public Point3D zero() { - super.zero(); + x = 0; + y = 0; z = 0; return this; }