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 Intersectionclosest(java.util.List<Intersection> intersections)Returns the closest intersection to this ray's source from the given intersections.booleanequals(java.lang.Object o)Compares the source and direction of the twoRays.inthashCode()Computes the hash code based on that of the sourcePointand the directionNonZeroVector.java.lang.StringtoString()Returns a string representing the source and direction as a tuple.protected booleanwithinDistance(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
travelMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
Ray
- Parameters:
start- ThePointat which theRaystarts.direction- TheNormalizedVectorin which theRayis 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:LineSegmentReturns whether or not some given distance traveled from the start along the direction is within the length of the line segment.- Overrides:
withinDistancein 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 twoRays.- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()Computes the hash code based on that of the sourcePointand the directionNonZeroVector.- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()Returns a string representing the source and direction as a tuple.- Overrides:
toStringin classjava.lang.Object
-