## Documentation ¶

### Overview ¶

Package ray represents a ray, or line, which has an origin and direction.

### Index ¶

### Constants ¶

This section is empty.

### Variables ¶

This section is empty.

### Functions ¶

#### func Equals ¶

Equals returns true if both of the given rays have the same origin point and direction vector. Otherwise, returns false.

#### func SortIntersectionsAsc ¶

func SortIntersectionsAsc(intersections []*Intersection)

SortIntersectionsAsc sorts the passed intersections into ascending order.

#### func SortIntersectionsDesc ¶

func SortIntersectionsDesc(intersections []*Intersection)

SortIntersectionsDesc sorts the passed intersections into descending order.

### Types ¶

#### type Intersection ¶

type Intersection struct { // T represents the units +/- along a Ray where is intersected with Object. T float64 // Object is the Sphere that was intersected by a Ray at T units. Object *sphere.Sphere }

Intersection encapsulates an intersection of a ray with an object.

#### func Hit ¶

func Hit(intersections []*Intersection) *Intersection

Hit returns the Intersection with the lowest non-negative T value.

#### func Intersections ¶

func Intersections(intersections ...*Intersection) []*Intersection

Intersections returns a slice of the passed Intersections.

#### func NewIntersection ¶

func NewIntersection(t float64, object *sphere.Sphere) *Intersection

NewIntersection returns a new Intersection with the passed t value and object.

#### func RaySphereIntersect ¶

func RaySphereIntersect(r *Ray, s *sphere.Sphere) []*Intersection

RaySphereIntersect intersects the passed ray with the passed sphere.

It returns the t values (i.e., intersection units +/- away from the origin of the Ray) where the Ray intersects with the sphere.

If the ray intersects with the sphere at two points, then two different intersection t values are returned. If the ray intersects with the sphere at a single, tangent Point, then two equal t values are returned. If the ray does not intersect with the sphere, then an empty slice is returned.

#### type IntersectionComputations ¶

type IntersectionComputations struct { Intersection // The Point at which the ray intersected the object Point *point.Point // The OverPoint is the Point that has been slightly adjusted in // the direction of the NormalVec in order to avoid shadow acne from // self-intersection when determining if an intersection is in shadow. OverPoint *point.Point // The eye vector points in the opposite direction as the ray EyeVec *vector.Vector // The normal vector on the object surface at the Point of intersection NormalVec *vector.Vector // If Inside is true, the intersection occurred from Inside of the object. // Otherwise the intersection occurred from the outside of the object. Inside bool }

IntersectionComputations encapsulates some precomputed information related to an intersection.

Note:

This could potentially be in the intersection structure itself. It's directly related to an intersection and carries its T and Object values.

#### func PrepareComputations ¶

func PrepareComputations(i *Intersection, r *Ray) (*IntersectionComputations, error)

PrepareComputations computes and returns additional information related to an intersection.