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
TheNormalizedVector
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
ThePoint
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 ofsquareLength
(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
ThePoint
at which the ray starts. -
direction
TheNormalizedVector
which the ray is pointing towards. -
squareLength
public final double squareLengthThe square of the distance between the source and the light source. -
inverse
A precomputed vector where each coordinate is the inverse of the respective coordinate in the direction vector.
-
-
Constructor Details
-
LineSegment
Construct a line segment between start and end. -
LineSegment
Construct a line segment starting at start, heading in the given direction, with length equal to the square root ofsquareLength
(which may be infinity).- Parameters:
start
- ThePoint
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
Calculate the point along the line segment after traveling "distance" units in the line segment's direction. If the given distance squared is greater thansquareDistance
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.
-