Home Reference Source
import {Ray} from 'math-ds'
public class | source

Ray

A ray.

Constructor Summary

Public Constructor
public

constructor(origin: Vector3, direction: Vector3)

Constructs a new ray.

Member Summary

Public Members
public

The direction.

public

The origin.

Method Summary

Public Methods
public

Applies the given matrix to this ray.

public

at(t: Number, target: Vector3): Vector3

Computes a point along the ray based on a given scalar t.

public

clone(): Ray

Clones this ray.

public

Finds the closest point along this ray to a given point.

public

copy(r: Ray): Ray

Copies the given ray.

public

Calculates the squared distance from this ray to the given point.

public

distanceSquaredToSegment(v0: Vector3, v1: Vector3, pointOnRay: Vector3, pointOnSegment: Vector3): Number

Calculates the distance from this ray to a given line segment.

public

Calculates the distance from this ray to the given plane.

public

Calculates the distance from this ray to the given point.

public

Checks if this ray equals the given one.

public

Finds the point where this ray intersects the given box.

public

Finds the point where this ray intersects the given plane.

public

Finds the point where this ray intersects the given sphere.

public

intersectTriangle(a: Vector3, b: Vector3, c: Vector3, backfaceCulling: Boolean, target: Vector3): Vector3

Finds the point where this ray intersects the given triangle.

public

Determines whether this ray intersects the given box.

public

Determines whether this ray intersects the given plane.

public

Determines whether this ray intersects the given sphere.

public

lookAt(target: Vector3): Ray

Rotates this ray to look at the given target.

public

Moves the origin along the ray by a given scalar t.

public

set(origin: Vector3, direction: Vector3): Ray

Sets the origin and the direction.

Public Constructors

public constructor(origin: Vector3, direction: Vector3) source

Constructs a new ray.

Params:

NameTypeAttributeDescription
origin Vector3
  • optional

The origin.

direction Vector3
  • optional

The direction.

Public Members

public direction: Vector3 source

The direction.

public origin: Vector3 source

The origin.

Public Methods

public applyMatrix4(m: Matrix4): Ray source

Applies the given matrix to this ray.

Params:

NameTypeAttributeDescription
m Matrix4

A matrix.

Return:

Ray

This ray.

public at(t: Number, target: Vector3): Vector3 source

Computes a point along the ray based on a given scalar t.

Params:

NameTypeAttributeDescription
t Number

The scalar.

target Vector3
  • optional

A target vector. If none is provided, a new one will be created.

Return:

Vector3

The point.

public clone(): Ray source

Clones this ray.

Return:

Ray

The cloned ray.

public closestPointToPoint(p: Vector3, target: Vector3): Vector3 source

Finds the closest point along this ray to a given point.

Params:

NameTypeAttributeDescription
p Vector3

A point.

target Vector3
  • optional

A target vector. If none is provided, a new one will be created.

Return:

Vector3

The point.

public copy(r: Ray): Ray source

Copies the given ray.

Params:

NameTypeAttributeDescription
r Ray

A ray.

Return:

Ray

This ray.

public distanceSquaredToPoint(p: Vector3): Number source

Calculates the squared distance from this ray to the given point.

Params:

NameTypeAttributeDescription
p Vector3

The point.

Return:

Number

The squared distance.

public distanceSquaredToSegment(v0: Vector3, v1: Vector3, pointOnRay: Vector3, pointOnSegment: Vector3): Number source

Calculates the distance from this ray to a given line segment.

Based on: http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h

Params:

NameTypeAttributeDescription
v0 Vector3

The start of the segment.

v1 Vector3

The end of the segment.

pointOnRay Vector3
  • optional

If provided, the point on this Ray that is closest to the segment will be stored in this vector.

pointOnSegment Vector3
  • optional

If provided, the point on the line segment that is closest to this ray will be stored in this vector.

Return:

Number

The smallest distance between the ray and the segment defined by v0 and v1.

public distanceToPlane(p: Plane): Number source

Calculates the distance from this ray to the given plane.

Params:

NameTypeAttributeDescription
p Plane

The plane.

Return:

Number

The distance, or null if the denominator is zero.

public distanceToPoint(p: Vector3): Number source

Calculates the distance from this ray to the given point.

Params:

NameTypeAttributeDescription
p Vector3

The point.

Return:

Number

The distance.

public equals(r: Ray): Boolean source

Checks if this ray equals the given one.

Params:

NameTypeAttributeDescription
r Ray

A ray.

Return:

Boolean

Whether the rays are equal.

public intersectBox(b: Plane, target: Vector3): Vector3 source

Finds the point where this ray intersects the given box.

Params:

NameTypeAttributeDescription
b Plane

A box.

target Vector3
  • optional

A target vector. If none is provided, a new one will be created.

Return:

Vector3

The point of intersection, or null if there is none.

public intersectPlane(p: Plane, target: Vector3): Vector3 source

Finds the point where this ray intersects the given plane.

Params:

NameTypeAttributeDescription
p Plane

A plane.

target Vector3
  • optional

A target vector. If none is provided, a new one will be created.

Return:

Vector3

The point of intersection, or null if there is none.

public intersectSphere(s: Sphere, target: Vector3): Vector3 source

Finds the point where this ray intersects the given sphere.

Params:

NameTypeAttributeDescription
s Sphere

A sphere.

target Vector3
  • optional

A target vector. If none is provided, a new one will be created.

Return:

Vector3

The point of intersection, or null if there is none.

public intersectTriangle(a: Vector3, b: Vector3, c: Vector3, backfaceCulling: Boolean, target: Vector3): Vector3 source

Finds the point where this ray intersects the given triangle.

Based on: http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h

Params:

NameTypeAttributeDescription
a Vector3

A triangle vertex.

b Vector3

A triangle vertex.

c Vector3

A triangle vertex.

backfaceCulling Boolean
  • optional
  • default: false

Whether backface culling should be considered.

target Vector3
  • optional

A target vector. If none is provided, a new one will be created.

Return:

Vector3

The point of intersection, or null if there is none.

public intersectsBox(b: Box3): Boolean source

Determines whether this ray intersects the given box.

Params:

NameTypeAttributeDescription
b Box3

A box.

Return:

Boolean

Whether this ray intersects the given box.

public intersectsPlane(p: Plane): Boolean source

Determines whether this ray intersects the given plane.

Params:

NameTypeAttributeDescription
p Plane

A plane.

Return:

Boolean

Whether this ray intersects the given plane.

public intersectsSphere(s: Sphere): Boolean source

Determines whether this ray intersects the given sphere.

Params:

NameTypeAttributeDescription
s Sphere

A sphere.

Return:

Boolean

Whether this ray intersects the given sphere.

public lookAt(target: Vector3): Ray source

Rotates this ray to look at the given target.

Params:

NameTypeAttributeDescription
target Vector3

A point to look at.

Return:

Ray

This ray.

public recast(t: Number): Ray source

Moves the origin along the ray by a given scalar t.

Params:

NameTypeAttributeDescription
t Number

The scalar.

Return:

Ray

This ray.

public set(origin: Vector3, direction: Vector3): Ray source

Sets the origin and the direction.

Params:

NameTypeAttributeDescription
origin Vector3

The origin.

direction Vector3

The direction. Should be normalized.

Return:

Ray

This ray.