Class Point3D

java.lang.Object
org.jlab.geom.prim.Point3D
All Implemented Interfaces:
Transformable, Showable

public final class Point3D extends Object implements Transformable, Showable
A 3D point in space represented by three coordinates coordinates (x, y, z).

The distance between two points can be obtained via distance(org.jlab.geom.prim.Point3D). It is also possible to linearly interpolate between one point an another via lerp(Point3D, double), and to vector from one point to another via vectorTo(Point3D) and vectorFrom(Point3D). Also, any collection of points can be averaged using average(java.util.Collection).

Author:
gavalian
  • Constructor Summary Link icon

    Constructors
    Constructor
    Description
    Constructs a new Point3D at (0, 0, 0).
    Point3D(double x, double y, double z)
    Constructs a new Point3D at (x, y, z).
    Constructs a new Point3D by copying the x, y, and z coordinates of the given point.
    Point3D(Point3D point, Vector3D vector)
    Constructs a new Point3D by adding the given vector to the given point.
    Constructs a new Point3D with the given vector.
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    static Point3D
    Constructs a new Point3D at the geometric mean of the given points.
    static Point3D
    average(Point3D... points)
    Constructs a new Point3D at the geometric mean of the given points.
    void
    Combines this point with the given point.
    void
    copy(Point3D point)
    Sets the components of this point to be equal the components of the given point.
    double
    distance(double x, double y, double z)
    Returns the distance between this point and the point at the given coordinate.
    double
    Returns the distance between this point and the given point.
    lerp(Point3D point, double t)
    Constructs a new Point3D between this point and the given point by linearly interpolating from this point to the given point by the amount specified.
    Constructs a new Point3D at the geometric mean of this point and the given point.
    void
    rotateX(double angle)
    Rotates this object clockwise around the x axis.
    void
    rotateY(double angle)
    Rotates this object clockwise around the y axis.
    void
    rotateZ(double angle)
    Rotates this object clockwise around the z axis.
    void
    set(double x, double y, double z)
    Sets the x, y and z coordinates of this point.
    void
    set(Point3D point, Vector3D vector)
    Sets this points coordinates by adding the given vector to the given point.
    void
    setX(double x)
    Sets the x coordinate.
    void
    setY(double y)
    Sets the y coordinate.
    void
    setZ(double z)
    Sets the z coordinate.
    void
    Invokes System.out.println(this).
     
     
    toStringBrief(int ndigits)
     
    Constructs a new Vector3D using this points x, y, and z coordinates.
    void
    translateXYZ(double x, double y, double z)
    Translates this object linearly by the amounts specified.
    vectorFrom(double x, double y, double z)
    Constructs a new Vector3D point from the point at the given coordinates to this point (this.x-x, this.y-y, this.z-z)
    Constructs a new Vector3D pointing from the given point to this point (equivalent to (this.x-point.x, this.y-point.y, this.z-point.z).
    vectorTo(double x, double y, double z)
    Constructs a new Vector3D point from this point to the point at the given coordinates (x-this.x, y-this.y, z-this.z)).
    Constructs a new Vector3D pointing from this point to the given point (equivalent to (point.x-this.x, point.y-this.y, point.z-this.z)).
    double
    x()
    Returns the x coordinate.
    double
    y()
    Returns the y coordinate.
    double
    z()
    Returns the z coordinate.

    Methods inherited from class java.lang.Object Link icon

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details Link icon

    • Point3D Link icon

      public Point3D()
      Constructs a new Point3D at (0, 0, 0).
    • Point3D Link icon

      public Point3D(double x, double y, double z)
      Constructs a new Point3D at (x, y, z).
      Parameters:
      x - the x coordinate
      y - the y coordinate
      z - the z coordinate
    • Point3D Link icon

      public Point3D(Vector3D v)
      Constructs a new Point3D with the given vector.
      Parameters:
      v - the vector
    • Point3D Link icon

      public Point3D(Point3D point, Vector3D vector)
      Constructs a new Point3D by adding the given vector to the given point.
      Parameters:
      point - the origin point
      vector - the direction vector
    • Point3D Link icon

      public Point3D(Point3D point)
      Constructs a new Point3D by copying the x, y, and z coordinates of the given point.
      Parameters:
      point - the point to copy
  • Method Details Link icon

    • copy Link icon

      public void copy(Point3D point)
      Sets the components of this point to be equal the components of the given point.
      Parameters:
      point - the point to copy
    • set Link icon

      public void set(Point3D point, Vector3D vector)
      Sets this points coordinates by adding the given vector to the given point.
      Parameters:
      point - the origin point
      vector - the direction vector
    • set Link icon

      public void set(double x, double y, double z)
      Sets the x, y and z coordinates of this point.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      z - the z coordinate
    • setX Link icon

      public void setX(double x)
      Sets the x coordinate.
      Parameters:
      x - the x coordinate
    • setY Link icon

      public void setY(double y)
      Sets the y coordinate.
      Parameters:
      y - the y coordinate
    • setZ Link icon

      public void setZ(double z)
      Sets the z coordinate.
      Parameters:
      z - the z coordinate
    • x Link icon

      public double x()
      Returns the x coordinate.
      Returns:
      the x coordinate
    • y Link icon

      public double y()
      Returns the y coordinate.
      Returns:
      the y coordinate
    • z Link icon

      public double z()
      Returns the z coordinate.
      Returns:
      the z coordinate
    • distance Link icon

      public double distance(Point3D point)
      Returns the distance between this point and the given point.
      Parameters:
      point - the point to calculate the distance from this point to
      Returns:
      the distance between the points
    • distance Link icon

      public double distance(double x, double y, double z)
      Returns the distance between this point and the point at the given coordinate.
      Parameters:
      x - the x coordinate of the given point
      y - the y coordinate of the given point
      z - the z coordinate of the given point
      Returns:
      the distance between the points
    • midpoint Link icon

      public Point3D midpoint(Point3D point)
      Constructs a new Point3D at the geometric mean of this point and the given point. This function behaves identically to lerp(point, 0.5).
      Parameters:
      point - the other point
      Returns:
      a point at the geometric mean of the two given points
    • lerp Link icon

      public Point3D lerp(Point3D point, double t)
      Constructs a new Point3D between this point and the given point by linearly interpolating from this point to the given point by the amount specified.
      • If t==0, then the returned point is equal to this point.
      • If t==0.5, then the returned point is half way between both points.
      • If t==1, then the returned point is equal to the given point.
      Parameters:
      point - the point to interpolate between
      t - the interpolation coefficient
      Returns:
      the newly constructed point
    • combine Link icon

      public void combine(Point3D point)
      Combines this point with the given point. The position of this point will move to the geometric mean (midpoint) of the the two points.
      Parameters:
      point - the point used to calculate the geometric mean
    • vectorFrom Link icon

      public Vector3D vectorFrom(Point3D point)
      Constructs a new Vector3D pointing from the given point to this point (equivalent to (this.x-point.x, this.y-point.y, this.z-point.z).
      Parameters:
      point - the given point
      Returns:
      the direction vector from the given point to this point
    • vectorFrom Link icon

      public Vector3D vectorFrom(double x, double y, double z)
      Constructs a new Vector3D point from the point at the given coordinates to this point (this.x-x, this.y-y, this.z-z)
      Parameters:
      x - the x coordinate of the given point
      y - the y coordinate of the given point
      z - the z coordinate of the given point
      Returns:
      the direction vector from the given point to this point
    • vectorTo Link icon

      public Vector3D vectorTo(Point3D point)
      Constructs a new Vector3D pointing from this point to the given point (equivalent to (point.x-this.x, point.y-this.y, point.z-this.z)).
      Parameters:
      point - the given point
      Returns:
      the direction vector from this point to the given
    • vectorTo Link icon

      public Vector3D vectorTo(double x, double y, double z)
      Constructs a new Vector3D point from this point to the point at the given coordinates (x-this.x, y-this.y, z-this.z)).
      Parameters:
      x - the x coordinate of the given point
      y - the y coordinate of the given point
      z - the z coordinate of the given point
      Returns:
      the direction vector from this point to the given
    • toVector3D Link icon

      public Vector3D toVector3D()
      Constructs a new Vector3D using this points x, y, and z coordinates.
      Returns:
      a vector representation of this point
    • translateXYZ Link icon

      public void translateXYZ(double x, double y, double z)
      Description copied from interface: Transformable
      Translates this object linearly by the amounts specified.
      Specified by:
      translateXYZ in interface Transformable
      Parameters:
      x - amount to translate along the x axis
      y - amount to translate along the y axis
      z - amount to translate along the z axis
    • rotateX Link icon

      public void rotateX(double angle)
      Description copied from interface: Transformable
      Rotates this object clockwise around the x axis.
      Specified by:
      rotateX in interface Transformable
      Parameters:
      angle - rotation angle in radians
    • rotateY Link icon

      public void rotateY(double angle)
      Description copied from interface: Transformable
      Rotates this object clockwise around the y axis.
      Specified by:
      rotateY in interface Transformable
      Parameters:
      angle - rotation angle in radians
    • rotateZ Link icon

      public void rotateZ(double angle)
      Description copied from interface: Transformable
      Rotates this object clockwise around the z axis.
      Specified by:
      rotateZ in interface Transformable
      Parameters:
      angle - rotation angle in radians
    • average Link icon

      public static Point3D average(Point3D... points)
      Constructs a new Point3D at the geometric mean of the given points.
      Parameters:
      points - the points to average
      Returns:
      the geometric mean of the points
    • average Link icon

      public static Point3D average(Collection<Point3D> points)
      Constructs a new Point3D at the geometric mean of the given points.
      Parameters:
      points - the points to average
      Returns:
      the geometric mean of the points
    • show Link icon

      public void show()
      Invokes System.out.println(this).
      Specified by:
      show in interface Showable
    • toString Link icon

      public String toString()
      Overrides:
      toString in class Object
    • toStringBrief Link icon

      public String toStringBrief(int ndigits)
    • toStringBrief Link icon

      public String toStringBrief()