Skip to content

Documentation / base / Ray

Class: Ray

Defined in: libs/base/src/math/ray.ts:18

The ray class

Constructors

Constructor

new Ray(origin?, directionNormalized?): Ray

Defined in: libs/base/src/math/ray.ts:72

Construct a ray from origin and normalized direction vector.

Parameters

origin?

Vector3

The ray origin if not specified, zero vector will be used.

directionNormalized?

Vector3

The normalized direction vector. if not specified, (0, 0, 1) will be used.

Returns

Ray

Properties

bboxIntersectionTest

bboxIntersectionTest: (bbox) => boolean

Defined in: libs/base/src/math/ray.ts:59

Do a intersection test with an AABB.

Parameters

bbox

AABB

The box to be test.

Returns

boolean

true if the ray intersect with the box, otherwise false.


bboxIntersectionTestEx

bboxIntersectionTestEx: (bbox, axisInfo?) => number

Defined in: libs/base/src/math/ray.ts:65

Do a intersection test with an AABB.

Parameters

bbox

AABB

The box to be test.

axisInfo?
axis?

CubeFace

Returns

number

The distance from the origin to intersected point if the ray intersect with the box, otherwise null.

Accessors

origin

Get Signature

get origin(): Vector3

Defined in: libs/base/src/math/ray.ts:78

Get the ray origin point

Returns

Vector3


direction

Get Signature

get direction(): Vector3

Defined in: libs/base/src/math/ray.ts:82

Get the ray direction vector

Returns

Vector3

Methods

set()

set(origin, directionNormalized): void

Defined in: libs/base/src/math/ray.ts:90

Set the ray origin and normalized direction vector.

Parameters

origin

Vector3

The ray origin point.

directionNormalized

Vector3

The normalized direction vector.

Returns

void


transform()

transform(matrix, other?): Ray

Defined in: libs/base/src/math/ray.ts:101

Transform the ray.

Parameters

matrix

Matrix4x4

The transform matrix.

other?

Ray

A ray object to which the result will be written, if not specified, a new ray object will be returned.

Returns

Ray

The transform result.


intersectionTestCircle()

intersectionTestCircle(center, normal, radius, epsl): object

Defined in: libs/base/src/math/ray.ts:124

Parameters

center

Vector3

normal

Vector3

radius

number

epsl

number

Returns

object

dist

dist: number = d

epsl

epsl: number = t


intersectionTestPlane()

intersectionTestPlane(plane): number

Defined in: libs/base/src/math/ray.ts:189

Do a ray-plane intersection test.

The plane is defined by the equation Ax + By + Cz + D = 0 where (A, B, C) is the plane normal (assumed to be normalised) and D is the signed distance offset stored in plane.d.

Parameters

plane

Plane

The plane to test against.

Returns

number

The distance t from the ray origin to the intersection point (i.e. the hit point is origin + t * direction), or null when there is no intersection in the forward direction (t < 0) or the ray is parallel to the plane.


intersectionTestSphere()

intersectionTestSphere(center, radius): number[]

Defined in: libs/base/src/math/ray.ts:211

Do a ray sphere intersection test

Parameters

center

Vector3

radius

number

Sphere radius

Returns

number[]

Distance from origin to the intersected point if the ray intersects with the sphere, otherwise null


intersectionTestTriangle()

intersectionTestTriangle(v1, v2, v3, cull): number

Defined in: libs/base/src/math/ray.ts:248

Do a ray triangle intersection test.

Parameters

v1

Vector3

The first triangle vertex.

v2

Vector3

The second triangle vertex.

v3

Vector3

The third triangle vertex.

cull

boolean

Allow back side intersection if true.

Returns

number

Distance from origin to the intersected point if the ray intersects with the triangle, otherwise null.

Released under the MIT License.