Class Point3D

java.lang.Object
eu.svjatoslav.sixth.e3d.geometry.Point3D
All Implemented Interfaces:
Cloneable

public class Point3D extends Object implements 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
    Modifier and Type
    Field
    Description
    double
    X coordinate (horizontal axis).
    double
    Y coordinate (vertical axis, positive = down in screen space).
    double
    Z coordinate (depth axis, positive = into the screen / away from viewer).
  • Constructor Summary

    Constructors
    Constructor
    Description
    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).
    Point3D(Point3D parent)
    Creates new current point by cloning coordinates from parent point.
    Creates a point from an IntegerPoint (used by octree voxel coordinates).
  • Method Summary

    Modifier and Type
    Method
    Description
    add(Point3D otherPoint)
    Add other point to current point.
    addTo(Point3D... otherPoints)
    Add coordinates of current point to other point.
    Create new point by cloning position of current point.
    clone(Point3D otherPoint)
    Copy coordinates from other point to current point.
    Set current point coordinates to the middle point between two other points.
    double
    getAngleXY(Point3D anotherPoint)
    Computes the angle on the X-Y plane between this point and another point.
    double
    getAngleXZ(Point3D anotherPoint)
    Computes the angle on the X-Z plane between this point and another point.
    double
    getAngleYZ(Point3D anotherPoint)
    Computes the angle on the Y-Z plane between this point and another point.
    double
    getDistanceTo(Point3D anotherPoint)
    Compute distance to another point.
    double
     
    Invert current point coordinates.
    boolean
    Here we assume that Z coordinate is distance to the viewer.
    boolean
     
    rotate(double angleXZ, double angleYZ)
    Rotate current point around the origin by the given angles.
    rotate(Point3D center, double angleXZ, double angleYZ)
    Rotate current point around center point by angleXZ and angleYZ.
    void
    Round current point coordinates to integer values.
    scaleDown(double factor)
    Scale down current point by factor.
    scaleUp(double factor)
    Scale up current point by factor.
    void
    setValues(double x, double y, double z)
    Set current point coordinates to given values.
    subtract(Point3D otherPoint)
    Subtract other point from current point.
     
    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.
    Resets point coordinates to zero along all axes.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • x

      public double x
      X coordinate (horizontal axis).
    • y

      public double y
      Y coordinate (vertical axis, positive = down in screen space).
    • z

      public double z
      Z 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 coordinate
      y - the Y coordinate
      z - 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 coordinate
      y - the Y coordinate
      z - 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 coordinate
      y - the Y coordinate
      z - the Z coordinate
    • Point3D

      public Point3D(IntegerPoint point)
      Creates a point from an IntegerPoint (used by octree voxel coordinates).
      Parameters:
      point - the integer point to convert
    • Point3D

      public Point3D(Point3D parent)
      Creates new current point by cloning coordinates from parent point.
  • Method Details

    • add

      public Point3D add(Point3D otherPoint)
      Add other point to current point. Value of other point will not be changed.
      Parameters:
      otherPoint - point to add.
      Returns:
      current point.
    • addTo

      public Point3D addTo(Point3D... otherPoints)
      Add coordinates of current point to other point. Value of current point will not be changed.
      Returns:
      current point.
    • clone

      public Point3D clone()
      Create new point by cloning position of current point.
      Overrides:
      clone in class Object
      Returns:
      newly created clone.
    • clone

      public Point3D clone(Point3D otherPoint)
      Copy coordinates from other point to current point. Value of other point will not be changed.
    • computeMiddlePoint

      public Point3D computeMiddlePoint(Point3D p1, Point3D p2)
      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

      public double getAngleXZ(Point3D anotherPoint)
      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

      public double getAngleYZ(Point3D anotherPoint)
      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

      public double getAngleXY(Point3D anotherPoint)
      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

      public double getDistanceTo(Point3D anotherPoint)
      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

      public Point3D invert()
      Invert current point coordinates.
      Returns:
      current point.
    • rotate

      public Point3D rotate(Point3D center, double angleXZ, double angleYZ)
      Rotate current point around center point by angleXZ and angleYZ.

      See also: Let's remove Quaternions from every 3D Engine

      Parameters:
      center - center point.
      angleXZ - angle around XZ axis.
      angleYZ - angle around YZ axis.
    • rotate

      public Point3D rotate(double angleXZ, double angleYZ)
      Rotate current point around the origin by the given angles.
      Parameters:
      angleXZ - angle around the XZ plane (yaw), in radians
      angleYZ - angle around the YZ plane (pitch), in radians
      Returns:
      this point (mutated)
    • roundToInteger

      public void roundToInteger()
      Round current point coordinates to integer values.
    • scaleDown

      public Point3D scaleDown(double factor)
      Scale down current point by factor. All coordinates will be divided by factor.
      Parameters:
      factor - factor to scale by.
      Returns:
      current point.
    • scaleUp

      public Point3D scaleUp(double factor)
      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

      public Point3D subtract(Point3D otherPoint)
      Subtract other point from current point. Value of other point will not be changed.
      Returns:
      current point.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • translateX

      public Point3D translateX(double xIncrement)
      Translate current point along X axis by given increment.
      Returns:
      current point.
    • translateY

      public Point3D translateY(double yIncrement)
      Translate current point along Y axis by given increment.
      Returns:
      current point.
    • translateZ

      public Point3D translateZ(double zIncrement)
      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

      public Point3D zero()
      Resets point coordinates to zero along all axes.
      Returns:
      current point.