Package primitives
Class Ray
java.lang.Object
primitives.LineSegment
primitives.Ray
public class Ray extends LineSegment
The
Ray
class represents a ray with it's base at the Point
'source' and shoots off in direction pointed at by NonZeroVector
'direction'.-
Field Summary
Fields inherited from class primitives.LineSegment
direction, inverse, squareLength, start
-
Constructor Summary
Constructors Constructor Description Ray(Point start, NormalizedVector direction)
-
Method Summary
Modifier and Type Method Description Intersection
closest(java.util.List<Intersection> intersections)
Returns the closest intersection to this ray's source from the given intersections.boolean
equals(java.lang.Object o)
Compares the source and direction of the twoRay
s.int
hashCode()
Computes the hash code based on that of the sourcePoint
and the directionNonZeroVector
.java.lang.String
toString()
Returns a string representing the source and direction as a tuple.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 primitives.LineSegment
travel
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
Ray
- Parameters:
start
- ThePoint
at which theRay
starts.direction
- TheNormalizedVector
in which theRay
is directed.
-
-
Method Details
-
closest
Returns the closest intersection to this ray's source from the given intersections.- Parameters:
intersections
- The intersections from which to get the closest one.- Returns:
- The closest intersection to the source of the ray.
- Throws:
java.util.NoSuchElementException
- if the list is empty.
-
withinDistance
protected boolean withinDistance(double distance)Description copied from class:LineSegment
Returns whether or not some given distance traveled from the start along the direction is within the length of the line segment.- Overrides:
withinDistance
in classLineSegment
- Parameters:
distance
- The distance traveled from the start along the direction.- Returns:
- whether or not the distance squared is less than squareDistance.
-
equals
public boolean equals(java.lang.Object o)Compares the source and direction of the twoRay
s.- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()Computes the hash code based on that of the sourcePoint
and the directionNonZeroVector
.- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()Returns a string representing the source and direction as a tuple.- Overrides:
toString
in classjava.lang.Object
-