X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Fgeometry%2FPoint3D.java;h=8d723454c453370682e01c91f7a7cc2b9cc58e9e;hb=ff13a51ec53b3d2ee1c9309152ed2b40366218b9;hp=e2c9868c0c696f707418dd111c6ec9687de6d6d2;hpb=0f7068dde61bcdbee69782182607015132dc1060;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 e2c9868..8d72345 100755 --- a/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/geometry/Point3D.java @@ -12,6 +12,7 @@ import static java.lang.Math.*; public class Point3D implements Cloneable { + // coordinates public double x, y, z; public Point3D() { @@ -45,8 +46,9 @@ public class Point3D implements Cloneable { } /** - * Add other point to current point. + * Add other point to current point. Value of other point will not be changed. * + * @param otherPoint point to add. * @return current point. */ public Point3D add(final Point3D otherPoint) { @@ -60,13 +62,23 @@ public class Point3D implements Cloneable { return new Point3D(this); } - public Point3D clone(final Point3D parent) { - x = parent.x; - y = parent.y; - z = parent.z; + /** + * Copy coordinates from other point to current point. Value of other point will not be changed. + */ + public Point3D clone(final Point3D otherPoint) { + x = otherPoint.x; + y = otherPoint.y; + z = otherPoint.z; return this; } + /** + * Set current point coordinates to the middle point between two other points. + * + * @param p1 first point. + * @param p2 second point. + * @return current point. + */ public Point3D computeMiddlePoint(final Point3D p1, final Point3D p2) { x = (p1.x + p2.x) / 2d; y = (p1.y + p2.y) / 2d; @@ -74,6 +86,9 @@ public class Point3D implements Cloneable { return this; } + /** + * @return true if current point coordinates are equal to zero. + */ public boolean isZero() { return (x == 0) && (y == 0) && (z == 0); } @@ -92,6 +107,9 @@ public class Point3D implements Cloneable { /** * Compute distance to another point. + * + * @param anotherPoint point to compute distance to. + * @return distance to another point. */ public double getDistanceTo(final Point3D anotherPoint) { final double xDelta = x - anotherPoint.x; @@ -101,10 +119,18 @@ public class Point3D implements Cloneable { return sqrt(((xDelta * xDelta) + (yDelta * yDelta) + (zDelta * zDelta))); } + /** + * @return length of current vector. + */ public double getVectorLength() { return sqrt(((x * x) + (y * y) + (z * z))); } + /** + * Invert current point coordinates. + * + * @return current point. + */ public Point3D invert() { x = -x; y = -y; @@ -112,7 +138,16 @@ public class Point3D implements Cloneable { return this; } - public void rotate(final Point3D center, final double angleXZ, + /** + * Rotate current point around center point by angleXZ and angleYZ. + *

+ * See also: Let's remove Quaternions from every 3D Engine + * + * @param center center point. + * @param angleXZ angle around XZ axis. + * @param angleYZ angle around YZ axis. + */ + public Point3D rotate(final Point3D center, final double angleXZ, final double angleYZ) { final double s1 = sin(angleXZ); final double c1 = cos(angleXZ); @@ -133,14 +168,30 @@ public class Point3D implements Cloneable { x = x1 + center.x; y = y1 + center.y; z = z2 + center.z; + + return this; + } + + public Point3D rotate(final double angleXZ, final double angleYZ) { + return rotate(new Point3D(0, 0, 0), angleXZ, angleYZ); } + /** + * Round current point coordinates to integer values. + */ public void roundToInteger() { x = (int) x; y = (int) y; z = (int) z; } + /** + * Scale down current point by factor. + * All coordinates will be divided by factor. + * + * @param factor factor to scale by. + * @return current point. + */ public Point3D scaleDown(final double factor) { x /= factor; y /= factor; @@ -148,6 +199,13 @@ public class Point3D implements Cloneable { return this; } + /** + * Scale up current point by factor. + * All coordinates will be multiplied by factor. + * + * @param factor factor to scale by. + * @return current point. + */ public Point3D scaleUp(final double factor) { x *= factor; y *= factor; @@ -155,6 +213,12 @@ public class Point3D implements Cloneable { return this; } + /** + * Set current point coordinates to given values. + * @param x X coordinate. + * @param y Y coordinate. + * @param z Z coordinate. + */ public void setValues(final double x, final double y, final double z) { this.x = x; this.y = y; @@ -162,7 +226,7 @@ public class Point3D implements Cloneable { } /** - * Subtract other point from current point. + * Subtract other point from current point. Value of other point will not be changed. * * @return current point. */ @@ -179,6 +243,8 @@ public class Point3D implements Cloneable { } /** + * Translate current point along X axis by given increment. + * * @return current point. */ public Point3D translateX(final double xIncrement) { @@ -187,6 +253,8 @@ public class Point3D implements Cloneable { } /** + * Translate current point along Y axis by given increment. + * * @return current point. */ public Point3D translateY(final double yIncrement) { @@ -195,6 +263,8 @@ public class Point3D implements Cloneable { } /** + * Translate current point along Z axis by given increment. + * * @return current point. */ public Point3D translateZ(final double zIncrement) { @@ -213,7 +283,7 @@ public class Point3D implements Cloneable { } /** - * Resets point to 0 coordinate in X, Y and Z axis. + * Resets point coordinates to zero along all axes. * * @return current point. */