Package primitives

Class LineSegment

java.lang.Object
primitives.LineSegment
Direct Known Subclasses:
Ray

public class LineSegment
extends java.lang.Object
A straight line segment between two points.
  • Field Summary

    Fields
    Modifier and Type Field Description
    NormalizedVector direction
    The NormalizedVector which the ray is pointing towards.
    Vector inverse
    A precomputed vector where each coordinate is the inverse of the respective coordinate in the direction vector.
    double squareLength
    The square of the distance between the source and the light source.
    Point start
    The Point at which the ray starts.
  • Constructor Summary

    Constructors
    Constructor Description
    LineSegment​(Point start, NormalizedVector direction, double squareLength)
    Construct a line segment starting at start, heading in the given direction, with length equal to the square root of squareLength (which may be infinity).
    LineSegment​(Point start, Point end)
    Construct a line segment between start and end.
  • Method Summary

    Modifier and Type Method Description
    Point travel​(double distance)
    Calculate the point along the line segment after traveling "distance" units in the line segment's direction.
    protected boolean withinDistance​(double distance)
    Returns whether or not some given distance traveled from the start along the direction is within the length of the line segment.

    Methods inherited from class java.lang.Object

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

    • start

      public final Point start
      The Point at which the ray starts.
    • direction

      public final NormalizedVector direction
      The NormalizedVector which the ray is pointing towards.
    • squareLength

      public final double squareLength
      The square of the distance between the source and the light source.
    • inverse

      public final Vector inverse
      A precomputed vector where each coordinate is the inverse of the respective coordinate in the direction vector.
  • Constructor Details

    • LineSegment

      public LineSegment​(Point start, Point end)
      Construct a line segment between start and end.
      Parameters:
      start - The Point where the line segment starts.
      end - The Point where the line segment ends.
    • LineSegment

      public LineSegment​(Point start, NormalizedVector direction, double squareLength)
      Construct a line segment starting at start, heading in the given direction, with length equal to the square root of squareLength (which may be infinity).
      Parameters:
      start - The Point where the line segment starts.
      direction - The direction from the start to the end of the line segment.
      squareLength - The square of the length of the line segment (may be infinity).
  • Method Details

    • travel

      public Point travel​(double distance)
      Calculate the point along the line segment after traveling "distance" units in the line segment's direction. If the given distance squared is greater than squareDistance then null is returned.
      Parameters:
      distance - The distance to travel in the line segment's direction.
      Returns:
      The point on the line segment after travelling distance units, or null if distance is longer than the line segment.
    • withinDistance

      protected boolean withinDistance​(double distance)
      Returns whether or not some given distance traveled from the start along the direction is within the length of the line segment.
      Parameters:
      distance - The distance traveled from the start along the direction.
      Returns:
      whether or not the distance squared is less than squareDistance.