Package eu.svjatoslav.sixth.e3d.geometry
Class Point3D
java.lang.Object
eu.svjatoslav.sixth.e3d.geometry.Point3D
- All Implemented Interfaces:
Cloneable
A mutable 3D point or vector with double-precision coordinates.
Point3D is the fundamental coordinate type used throughout the Sixth 3D engine.
It represents either a position in 3D space or a directional vector, with public
x, y, z fields for direct access.
All mutation methods return this for fluent chaining:
Point3D p = new Point3D(10, 20, 30)
.scaleUp(2.0)
.translateX(5)
.add(new Point3D(1, 1, 1));
// p is now (25, 41, 61)
Common operations:
// Create points
Point3D origin = new Point3D(); // (0, 0, 0)
Point3D pos = new Point3D(100, 200, 300);
Point3D copy = new Point3D(pos); // clone
// Measure distance
double dist = pos.getDistanceTo(origin);
// Rotation
pos.rotate(origin, Math.PI / 4, 0); // rotate 45 degrees on XZ plane
// Scale
pos.scaleUp(2.0); // double all coordinates
pos.scaleDown(2.0); // halve all coordinates
Warning: This class is mutable with public fields. Clone before storing references that should not be shared:
Point3D safeCopy = original.clone();
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPoint3D()Creates a point at the origin (0, 0, 0).Point3D(double x, double y, double z) Creates a point with the specified double-precision coordinates.Point3D(float x, float y, float z) Creates a point with the specified float coordinates (widened to double).Point3D(int x, int y, int z) Creates a point with the specified integer coordinates (widened to double).Creates new current point by cloning coordinates from parent point.Point3D(IntegerPoint point) Creates a point from anIntegerPoint(used by octree voxel coordinates). -
Method Summary
Modifier and TypeMethodDescriptionAdd other point to current point.Add coordinates of current point to other point.clone()Create new point by cloning position of current point.Copy coordinates from other point to current point.computeMiddlePoint(Point3D p1, Point3D p2) Set current point coordinates to the middle point between two other points.doublegetAngleXY(Point3D anotherPoint) Computes the angle on the X-Y plane between this point and another point.doublegetAngleXZ(Point3D anotherPoint) Computes the angle on the X-Z plane between this point and another point.doublegetAngleYZ(Point3D anotherPoint) Computes the angle on the Y-Z plane between this point and another point.doublegetDistanceTo(Point3D anotherPoint) Compute distance to another point.doubleinvert()Invert current point coordinates.booleanHere we assume that Z coordinate is distance to the viewer.booleanisZero()rotate(double angleXZ, double angleYZ) Rotate current point around the origin by the given angles.Rotate current point around center point by angleXZ and angleYZ.voidRound current point coordinates to integer values.scaleDown(double factor) Scale down current point by factor.scaleUp(double factor) Scale up current point by factor.voidsetValues(double x, double y, double z) Set current point coordinates to given values.Subtract other point from current point.toString()translateX(double xIncrement) Translate current point along X axis by given increment.translateY(double yIncrement) Translate current point along Y axis by given increment.translateZ(double zIncrement) Translate current point along Z axis by given increment.zero()Resets point coordinates to zero along all axes.
-
Field Details
-
x
public double xX coordinate (horizontal axis). -
y
public double yY coordinate (vertical axis, positive = down in screen space). -
z
public double zZ coordinate (depth axis, positive = into the screen / away from viewer).
-
-
Constructor Details
-
Point3D
public Point3D()Creates a point at the origin (0, 0, 0). -
Point3D
public Point3D(double x, double y, double z) Creates a point with the specified double-precision coordinates.- Parameters:
x- the X coordinatey- the Y coordinatez- the Z coordinate
-
Point3D
public Point3D(float x, float y, float z) Creates a point with the specified float coordinates (widened to double).- Parameters:
x- the X coordinatey- the Y coordinatez- the Z coordinate
-
Point3D
public Point3D(int x, int y, int z) Creates a point with the specified integer coordinates (widened to double).- Parameters:
x- the X coordinatey- the Y coordinatez- the Z coordinate
-
Point3D
Creates a point from anIntegerPoint(used by octree voxel coordinates).- Parameters:
point- the integer point to convert
-
Point3D
Creates new current point by cloning coordinates from parent point.
-
-
Method Details
-
add
Add other point to current point. Value of other point will not be changed.- Parameters:
otherPoint- point to add.- Returns:
- current point.
-
addTo
Add coordinates of current point to other point. Value of current point will not be changed.- Returns:
- current point.
-
clone
Create new point by cloning position of current point. -
clone
Copy coordinates from other point to current point. Value of other point will not be changed. -
computeMiddlePoint
Set current point coordinates to the middle point between two other points.- Parameters:
p1- first point.p2- second point.- Returns:
- current point.
-
isZero
public boolean isZero()- Returns:
- true if current point coordinates are equal to zero.
-
getAngleXZ
Computes the angle on the X-Z plane between this point and another point.- Parameters:
anotherPoint- the other point- Returns:
- the angle in radians
-
getAngleYZ
Computes the angle on the Y-Z plane between this point and another point.- Parameters:
anotherPoint- the other point- Returns:
- the angle in radians
-
getAngleXY
Computes the angle on the X-Y plane between this point and another point.- Parameters:
anotherPoint- the other point- Returns:
- the angle in radians
-
getDistanceTo
Compute distance to another point.- Parameters:
anotherPoint- point to compute distance to.- Returns:
- distance to another point.
-
getVectorLength
public double getVectorLength()- Returns:
- length of current vector.
-
invert
Invert current point coordinates.- Returns:
- current point.
-
rotate
Rotate current point around center point by angleXZ and angleYZ.- Parameters:
center- center point.angleXZ- angle around XZ axis.angleYZ- angle around YZ axis.
-
rotate
Rotate current point around the origin by the given angles.- Parameters:
angleXZ- angle around the XZ plane (yaw), in radiansangleYZ- angle around the YZ plane (pitch), in radians- Returns:
- this point (mutated)
-
roundToInteger
public void roundToInteger()Round current point coordinates to integer values. -
scaleDown
Scale down current point by factor. All coordinates will be divided by factor.- Parameters:
factor- factor to scale by.- Returns:
- current point.
-
scaleUp
Scale up current point by factor. All coordinates will be multiplied by factor.- Parameters:
factor- factor to scale by.- Returns:
- current point.
-
setValues
public void setValues(double x, double y, double z) Set current point coordinates to given values.- Parameters:
x- X coordinate.y- Y coordinate.z- Z coordinate.
-
subtract
Subtract other point from current point. Value of other point will not be changed.- Returns:
- current point.
-
toString
-
translateX
Translate current point along X axis by given increment.- Returns:
- current point.
-
translateY
Translate current point along Y axis by given increment.- Returns:
- current point.
-
translateZ
Translate current point along Z axis by given increment.- Returns:
- current point.
-
isVisible
public boolean isVisible()Here we assume that Z coordinate is distance to the viewer. If Z is positive, then point is in front of the viewer, and therefore it is visible.- Returns:
- point visibility status.
-
zero
Resets point coordinates to zero along all axes.- Returns:
- current point.
-