Skip to content

Vector3d

An immutable direction and length. Destructures as const [x, y, z] = vector.

  • Iterable<number>

new Vector3d(x?, y?, z?): Vector3d

Creates a vector from components, which default to 0.

number

number

number

Vector3d

readonly length: number

Length of the vector.


readonly x: number

X component.


readonly y: number

Y component.


readonly z: number

Z component.

[iterator](): Iterator<number>

Iterator<number>

Iterable.[iterator]


add(other): Vector3d

Component-wise sum.

Vector3dLike

Vector3d


angleBetween(other): number

Angle to another vector, in radians.

Vector3dLike

number


cross(other): Vector3d

Cross product.

Vector3dLike

Vector3d


dot(other): number

Dot product.

Vector3dLike

number


equals(other): boolean

Exact component equality.

Vector3dLike

boolean


negate(): Vector3d

The vector pointing the opposite way.

Vector3d


normalize(): Vector3d

A vector with the same direction and length 1. Throws RangeError for a zero vector.

Vector3d


scale(factor): Vector3d

Multiplies every component by factor.

number

Vector3d


subtract(other): Vector3d

Component-wise difference.

Vector3dLike

Vector3d


toArray(): [number, number, number]

The components as an [x, y, z] array.

[number, number, number]


transform(transformation): Vector3d

Applies a transformation without its translation.

Transformation

Vector3d


static from(value): Vector3d

Converts a tuple, or returns an existing vector unchanged.

Vector3dLike

Vector3d