Skip to content

Class: Ray

Ray

Constructors

Properties

Accessors

Methods

Constructors

constructor

new Ray(origin?, dir?): Ray

Build a new ray object

Parameters

NameTypeDescription
origin?Vector3Ray starting point
dir?Vector3Ray direction

Returns

Ray

Defined in

src/math/Ray.ts:34

Properties

origin

origin: Vector3

Ray starting point

Defined in

src/math/Ray.ts:16


length

length: number = Number.MAX_VALUE

length

Defined in

src/math/Ray.ts:21

Accessors

direction

get direction(): Vector3

Ray direction

Returns

Vector3

Defined in

src/math/Ray.ts:43

set direction(dir): void

Parameters

NameType
dirVector3

Returns

void

Defined in

src/math/Ray.ts:47

Methods

clone

clone(): Ray

Clone a new Ray object

Returns

Ray

Defined in

src/math/Ray.ts:56


intersectBox

intersectBox(box, target?): Vector3

Determine whether it intersects a bounding box

Parameters

NameTypeDescription
boxIBoundbounding box
target?Vector3-

Returns

Vector3

whether intersect

Defined in

src/math/Ray.ts:69


pointAt

pointAt(t, target?): Vector3

Calculate a point on the ray

Parameters

NameTypeDescription
tnumberLength scalar
target?Vector3output target

Returns

Vector3

result

Defined in

src/math/Ray.ts:120


copy

copy(src): this

Sets the ray to be a copy of the original ray

Parameters

NameTypeDescription
srcRayRay object source

Returns

this

New ray object

Defined in

src/math/Ray.ts:133


setApproxDirection

setApproxDirection(dir): void

Fast to the approximate ray direction

Parameters

NameTypeDescription
dirVector3direction

Returns

void

Defined in

src/math/Ray.ts:145


setOrigin

setOrigin(origin): void

Set ray origin

Parameters

NameTypeDescription
originVector3ray origin

Returns

void

Defined in

src/math/Ray.ts:153


getOrigin

getOrigin(): Vector3

Get ray origin

Returns

Vector3

Defined in

src/math/Ray.ts:160


getPoint

getPoint(t): Vector3

Gets the point at the specified position on the ray

Parameters

NameTypeDescription
tnumberLength position

Returns

Vector3

Returns a point at the specified location

Defined in

src/math/Ray.ts:169


sqrDistToPoint

sqrDistToPoint(P): number

Calculate the distance from a point

Parameters

NameTypeDescription
PVector3Specify Point

Returns

number

result

Defined in

src/math/Ray.ts:179


applyMatrix

applyMatrix(mat4): void

Applied matrix transformation

Parameters

NameTypeDescription
mat4Matrix4matrix

Returns

void

Defined in

src/math/Ray.ts:195


pointInTriangle

pointInTriangle(P, A, B, C): boolean

Calculates whether a specified point is inside a triangle

Parameters

NameTypeDescription
PVector3point
AVector3Triangle vertex 1
BVector3Triangle vertex 2
CVector3Triangle vertex 3

Returns

boolean

whether it is inside a triangle

Defined in

src/math/Ray.ts:212


intersectTriangle

intersectTriangle(orig, dir, face): Vector3

Determine whether a ray intersects a triangle

Parameters

NameTypeDescription
origVector3Ray starting point
dirVector3Ray direction
faceTriangletriangle

Returns

Vector3

point of intersection

Defined in

src/math/Ray.ts:257


intersectSphere

intersectSphere(o, dir, center, radius): Vector3

Determine whether a ray intersects the sphere

Parameters

NameTypeDescription
oVector3Ray starting point
dirVector3Ray direction
centerVector3Sphere center
radiusnumberradius of sphericity

Returns

Vector3

point of intersection

Defined in

src/math/Ray.ts:320


intersectionSegment

intersectionSegment(sega, segb, threshold): Object

A test of the intersection between a ray and a given line segment within a given tolerance (threshold)

Parameters

NameTypeDescription
segaVector3The first point of a line segment used to test the intersection
segbVector3The second point of a line segment used to test the intersection
thresholdnumberMargin, if the ray does not intersect the line segment but is close to the given threshold, the intersection is successful

Returns

Object

If there is an intersection, then the distance from the ray origin to the intersection, if there is no intersection, is -1

NameType
outVector3
lengthnumber

Defined in

src/math/Ray.ts:352