ray

package
Version: v0.0.0-...-1b60a0e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2019 License: MIT Imports: 8 Imported by: 0

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

func Equals(r1, r2 *Ray) bool

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

func Position

func Position(ray *Ray, t float64) *point.Point

Position returns the Point that lies any distance t along the passed ray.

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.

type Ray

type Ray struct {
	Origin    *point.Point
	Direction *vector.Vector
}

Ray is a ray, or line, which has an origin and direction.

func NewRay

func NewRay(origin point.Point, direction vector.Vector) *Ray

NewRay returns a new Ray having the passed origin and direction.

func Transform

func Transform(ray *Ray, m *matrix.Matrix) (*Ray, error)

Transform applies the passed 4x4 transformation Matrix to the passed Ray. Returns a new Ray with the transformed origin and direction.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL