Ray

A ray that emits from an origin in a certain direction. This is used by the Raycaster to assist with raycasting. Raycasting is used for mouse picking (working out what objects in the 3D space the mouse is over) amongst other things.

Constructor

new Ray(originopt, directionopt)

Parameters:
NameTypeAttributesDescription
originVector3<optional>

the origin of the Ray.

directionVector3<optional>

the direction of the Ray. This must be normalized (with Vector3.normalize) for the methods to operate properly.

Methods

applyMatrix4(matrix4) → {Ray}

Transform this Ray by the Matrix4.

Parameters:
NameTypeDescription
matrix4Matrix4

the Matrix4 to apply to this Ray.

Returns:
Type: 
Ray

at(t, optionalTargetopt) → {Vector3}

Get a Vector3 that is a given distance along this Ray.

Parameters:
NameTypeAttributesDescription
tnumber

the distance along the Ray to retrieve a position for.

optionalTargetVector3<optional>

the result will be copied into this Vector3.

Returns:
Type: 
Vector3

copy(ray) → {Ray}

Copies the origin and direction properties of ray into this ray.

Parameters:
NameTypeDescription
rayRay
Returns:
Type: 
Ray

distanceSqToPoint(point) → {number}

Get the squared distance of the closest approach between the Ray and the Vector3.

Parameters:
NameTypeDescription
pointVector3

the Vector3 to compute a distance to.

Returns:
Type: 
number

distanceToPlane(plane) → {number}

Get the distance of the closest approach between the Ray and the Plane.

Parameters:
NameTypeDescription
planePlane

the Plane to compute a distance to.

Returns:
Type: 
number

intersectBox(box, optionalTargetopt) → {Vector3}

Intersect this Ray with a Box3, returning the intersection point or null if there is no intersection.

Parameters:
NameTypeAttributesDescription
boxBox3

the Box3 to intersect with.

optionalTargetVector3<optional>

the result will be copied into this Vector3.

Returns:
Type: 
Vector3

intersectPlane(plane, optionalTargetopt) → {Vector3}

Intersect this Ray with a Plane, returning the intersection point or null if there is no intersection.

Parameters:
NameTypeAttributesDescription
planePlane

the Plane to intersect with.

optionalTargetVector3<optional>

the result will be copied into this Vector3.

Returns:
Type: 
Vector3

intersectSphere(sphere, optionalTargetopt) → {Vector3}

Intersect this Ray with a Sphere, returning the intersection point or null if there is no intersection.

Parameters:
NameTypeAttributesDescription
sphereSphere

the Sphere to intersect with.

optionalTargetVector3<optional>

the result will be copied into this Vector3.

Returns:
Type: 
Vector3

intersectTriangle(a, b, c, backfaceCulling, optionalTargetopt) → {Vector3}

Intersect this Ray with a triangle, returning the intersection point or null if there is no intersection.

Parameters:
NameTypeAttributesDescription
aVector3

The Vector3 point making up the triangle.

bVector3

The Vector3 point making up the triangle.

cVector3

The Vector3 point making up the triangle.

backfaceCullingboolean

whether to use backface culling.

optionalTargetVector3<optional>

the result will be copied into this Vector3.

Returns:
Type: 
Vector3

intersectsBox(box) → {boolean}

Return true if this Ray intersects with the Box3.

Parameters:
NameTypeDescription
boxBox3

the Box3 to intersect with.

Returns:
Type: 
boolean

intersectsPlane(plane) → {boolean}

Return true if this Ray intersects with the Plane.

Parameters:
NameTypeDescription
planePlane

the plane to intersect with.

Returns:
Type: 
boolean

intersectsSphere(sphere) → {boolean}

Return true if this Ray intersects with the Sphere.

Parameters:
NameTypeDescription
sphereSphere

the Sphere to intersect with.

Returns:
Type: 
boolean

set(origin, direction) → {Ray}

Sets this ray's origin and direction properties by copying the values from the given objects.

Parameters:
NameTypeDescription
originVector3

the origin of the Ray.

directionVector3

the direction of the Ray. This must be normalized (with Vector3.normalize) for the methods to operate properly.

Returns:
Type: 
Ray