Class Line3D

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

public final class Line3D extends Object implements Transformable, Showable
A 3D line represented by two points, the origin point and the end point. The line can be treated as an infinite line, a ray bounded by only the origin point, or a line segment bounded by both the origin point and the end point.

The direction of the line can be obtained via toVector(). Points on the line can be obtained via lerpPoint(double). Distances from the a line to a point and from one line to another line can be obtained via distance(Point3D) and distance(Line3D).

Author:
gavalian
  • Constructor Summary Link icon

    Constructors
    Constructor
    Description
    Constructs a new Line3D such that the new Line3D's bounding points both coincide at the origin.
    Line3D(double x0, double y0, double z0, double x1, double y1, double z1)
    Constructs a new such Line3D that the new Line3D's bounding points coincide with the points specified by the given coordinates.
    Line3D(Line3D line)
    Constructs a new Line3D such that the new Line3D's bounding points coincide with the given line's bounding points.
    Line3D(Point3D point0, Point3D point1)
    Constructs a new Line3D such that the new Line3D's bounding points coincide with the given points.
    Line3D(Point3D point, Vector3D direction)
    Constructs a new Line3D such that the the given point is at the origin of the line and the vector from the origin to the end of the line is equal to the given vector.
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    void
    copy(Line3D line)
    Sets the bounding points of this line to coincide with the bounding points of the given line.
    direction vector from begin to end point
    Constructs a new Line3D from this line to the given line such that the origin point of the constructed line coincides with this line, the end point of the constructed line coincides with the given line, and the length of the constructed line is minimal.
    Constructs a new Line3D from this infinite line to the given point such that the origin point of the constructed line coincides with this infinite line, the end point of the constructed line coincides with the given point, and the length of the constructed line is minimal.
    Constructs a new Line3D from this ray line to the given point such that the origin point of the constructed line coincides with this ray line, the end point of the constructed line coincides with the given point, and the length of the constructed line is minimal.
    Constructs a new Line3D from this line segment to the given point such that the origin point of the constructed line coincides with this line segment, the end point of the constructed line coincides with the given point, and the length of the constructed line is minimal.
    Constructs a new Line3D from this line segment to the given line segment such that the origin point of the constructed line coincides with this line segment, the end point of the constructed line segment coincides with the given line segment, and the length of the constructed line is minimal.
    end()
    Returns the end point.
    double
    Returns the length of this line.
    lerpPoint(double t)
    Constructs a new Point3D on the line by linearly interpolating from this point to the given point by the amount specified.
    Constructs a new Point3D at the midpoint between the two bounding points.
    Returns the origin point.
     
     
    projection of a point onto this line
    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 x0, double y0, double z0, double x1, double y1, double z1)
    Sets the origin and end points using the given coordinates.
    void
    set(Point3D point0, Point3D point1)
    Sets the line origin and end point to given points.
    void
    set(Point3D point, Vector3D direction)
    Sets the line origin at the given point and the end point at the position of the origin point plus the given vector.
    void
    setEnd(double x, double y, double z)
    Sets the end point.
    void
    setEnd(Point3D point1)
    Sets the end point.
    void
    setOrigin(double x, double y, double z)
    Sets the origin point.
    void
    Sets the origin point.
    void
    Invokes System.out.println(this).
     
    Returns a vector from the origin point to the end point.
    void
    translateXYZ(double x, double y, double z)
    Translates this object linearly by the amounts specified.

    Methods inherited from class java.lang.Object Link icon

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

    • Line3D Link icon

      public Line3D()
      Constructs a new Line3D such that the new Line3D's bounding points both coincide at the origin. This line will have zero length.
    • Line3D Link icon

      public Line3D(double x0, double y0, double z0, double x1, double y1, double z1)
      Constructs a new such Line3D that the new Line3D's bounding points coincide with the points specified by the given coordinates.
      Parameters:
      x0 - x component of the origin point
      y0 - y component of the origin point
      z0 - z component of the origin point
      x1 - x component of the end point
      y1 - y component of the end point
      z1 - z component of the end point
    • Line3D Link icon

      public Line3D(Point3D point0, Point3D point1)
      Constructs a new Line3D such that the new Line3D's bounding points coincide with the given points.
      Parameters:
      point0 - the origin point
      point1 - the end point
    • Line3D Link icon

      public Line3D(Point3D point, Vector3D direction)
      Constructs a new Line3D such that the the given point is at the origin of the line and the vector from the origin to the end of the line is equal to the given vector.
      Parameters:
      point - a point on the line
      direction - the direction of the line
    • Line3D Link icon

      public Line3D(Line3D line)
      Constructs a new Line3D such that the new Line3D's bounding points coincide with the given line's bounding points.
      Parameters:
      line - the line to copy
  • Method Details Link icon

    • copy Link icon

      public void copy(Line3D line)
      Sets the bounding points of this line to coincide with the bounding points of the given line.
      Parameters:
      line - the line to copy
    • set Link icon

      public void set(Point3D point, Vector3D direction)
      Sets the line origin at the given point and the end point at the position of the origin point plus the given vector.
      Parameters:
      point - the origin point
      direction - a vector from the origin point to the end point
    • set Link icon

      public void set(Point3D point0, Point3D point1)
      Sets the line origin and end point to given points.
      Parameters:
      point0 - the new origin point
      point1 - the new end point
    • setOrigin Link icon

      public void setOrigin(Point3D point0)
      Sets the origin point.
      Parameters:
      point0 - the new origin point
    • setEnd Link icon

      public void setEnd(Point3D point1)
      Sets the end point.
      Parameters:
      point1 - the new end point
    • set Link icon

      public void set(double x0, double y0, double z0, double x1, double y1, double z1)
      Sets the origin and end points using the given coordinates.
      Parameters:
      x0 - x component of the origin point
      y0 - y component of the origin point
      z0 - z component of the origin point
      x1 - x component of the end point
      y1 - y component of the end point
      z1 - z component of the end point
    • setOrigin Link icon

      public void setOrigin(double x, double y, double z)
      Sets the origin point.
      Parameters:
      x - the x coordinate of the origin point
      y - the y coordinate of the origin point
      z - the z coordinate of the origin point
    • setEnd Link icon

      public void setEnd(double x, double y, double z)
      Sets the end point.
      Parameters:
      x - the x coordinate of the end point
      y - the y coordinate of the end point
      z - the z coordinate of the end point
    • origin Link icon

      public Point3D origin()
      Returns the origin point.
      Returns:
      the origin point
    • originDir Link icon

      public Vector3D originDir()
    • end Link icon

      public Point3D end()
      Returns the end point.
      Returns:
      the end point
    • length Link icon

      public double length()
      Returns the length of this line.
      Returns:
      the distance from one bounding point to the other
    • midpoint Link icon

      public Point3D midpoint()
      Constructs a new Point3D at the midpoint between the two bounding points.
      Returns:
      the midpoint of this line
    • lerpPoint Link icon

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

      public Vector3D toVector()
      Returns a vector from the origin point to the end point.
      Returns:
      a vector from the origin point to the end point
    • distance Link icon

      public Line3D distance(Point3D point)
      Constructs a new Line3D from this infinite line to the given point such that the origin point of the constructed line coincides with this infinite line, the end point of the constructed line coincides with the given point, and the length of the constructed line is minimal.
      Parameters:
      point - the given point
      Returns:
      the line of closest approach
    • distanceRay Link icon

      public Line3D distanceRay(Point3D point)
      Constructs a new Line3D from this ray line to the given point such that the origin point of the constructed line coincides with this ray line, the end point of the constructed line coincides with the given point, and the length of the constructed line is minimal.
      Parameters:
      point - the given point
      Returns:
      the line of closest approach
    • distanceSegment Link icon

      public Line3D distanceSegment(Point3D point)
      Constructs a new Line3D from this line segment to the given point such that the origin point of the constructed line coincides with this line segment, the end point of the constructed line coincides with the given point, and the length of the constructed line is minimal.
      Parameters:
      point - the given point
      Returns:
      the line of closest approach
    • distance Link icon

      public Line3D distance(Line3D line)
      Constructs a new Line3D from this line to the given line such that the origin point of the constructed line coincides with this line, the end point of the constructed line coincides with the given line, and the length of the constructed line is minimal.
      Parameters:
      line - the given infinite line
      Returns:
      the line of closest approach
    • distanceSegments Link icon

      public Line3D distanceSegments(Line3D line)
      Constructs a new Line3D from this line segment to the given line segment such that the origin point of the constructed line coincides with this line segment, the end point of the constructed line segment coincides with the given line segment, and the length of the constructed line is minimal.
      Parameters:
      line - the given line segment
      Returns:
      the line of closest approach
    • 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
    • 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
    • direction Link icon

      public Vector3D direction()
      direction vector from begin to end point
    • projection Link icon

      public Point3D projection(Point3D p)
    • projection Link icon

      public Vector3D projection(Vector3D v)
      projection of a point onto this line