Skip to main content

Class: Vec3Math

3D vector mathematical operations.

Constructors

constructor

new Vec3Math(): Vec3Math

Returns

Vec3Math

Methods

abs

abs(v1): number

Gets the magnitude of a vector.

Parameters

NameTypeDescription
v1Readonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>The vector to get the magnitude for.

Returns

number

the vector's magnitude.

Defined in

src/sdk/math/VecMath.ts:458


add

add(v1, v2, out): Float64Array

Add one vector to another.

Parameters

NameTypeDescription
v1Readonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>The first vector.
v2Readonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>The second vector.
outFloat64ArrayThe vector to write the results to.

Returns

Float64Array

the vector sum.

Defined in

src/sdk/math/VecMath.ts:384


copy

copy(from, to): Float64Array

Copies one vector to another.

Parameters

NameTypeDescription
fromReadonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>The vector from which to copy.
toFloat64ArrayThe vector to which to copy.

Returns

Float64Array

the changed vector.

Defined in

src/sdk/math/VecMath.ts:512


create

create(): Float64Array

Creates a 3D vector initialized to [0, 0, 0].

Returns

Float64Array

A new 3D vector initialized to [0, 0, 0].

Defined in

src/sdk/math/VecMath.ts:308

create(x, y, z): Float64Array

Creates a 3D vector with specified x-, y-, and z- components.

Parameters

NameTypeDescription
xnumberThe x-component of the new vector.
ynumberThe y-component of the new vector.
znumberThe z-component of the new vector.

Returns

Float64Array

A new 3D vector with the specified components.

Defined in

src/sdk/math/VecMath.ts:316


cross

cross(v1, v2, out): Float64Array

Gets the cross product of two vectors.

Parameters

NameTypeDescription
v1Readonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>the first vector.
v2Readonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>the second vector.
outFloat64Arraythe vector to which to write the result.

Returns

Float64Array

the cross product.

Defined in

src/sdk/math/VecMath.ts:424


distance

distance(vec1, vec2): number

Gets the Euclidean distance between two vectors.

Parameters

NameTypeDescription
vec1Readonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>The first vector.
vec2Readonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>The second vector.

Returns

number

the Euclidean distance between the two vectors.

Defined in

src/sdk/math/VecMath.ts:483


dot

dot(v1, v2): number

Gets the dot product of two vectors.

Parameters

NameTypeDescription
v1Readonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>The first vector.
v2Readonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>The second vector.

Returns

number

The dot product of the vectors.

Defined in

src/sdk/math/VecMath.ts:413


equals

equals(vec1, vec2): boolean

Checks if two vectors are equal.

Parameters

NameTypeDescription
vec1Readonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>The first vector.
vec2Readonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>The second vector.

Returns

boolean

Whether the two vectors are equal.

Defined in

src/sdk/math/VecMath.ts:493


isFinite

isFinite(vec): boolean

Checks if a vector is finite. A vector is considered finite if all of its components are finite.

Parameters

NameTypeDescription
vecReadonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>The vector to check.

Returns

boolean

Whether the specified vector is finite.

Defined in

src/sdk/math/VecMath.ts:502


multScalar

multScalar(v1, scalar, out): Float64Array

Multiplies a vector by a scalar.

Parameters

NameTypeDescription
v1Readonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>The vector to multiply.
scalarnumberThe scalar to apply.
outFloat64ArrayThe vector to write the results to.

Returns

Float64Array

The scaled vector.

Defined in

src/sdk/math/VecMath.ts:445


normalize

normalize(v1, out): Float64Array

Normalizes the vector to a unit vector.

Parameters

NameTypeDescription
v1Readonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>The vector to normalize.
outFloat64ArrayThe vector to write the results to.

Returns

Float64Array

the normalized vector.

Defined in

src/sdk/math/VecMath.ts:468


phi

phi(vec): number

Gets the spherical angle phi (azimuthal angle) of a vector in radians.

Parameters

NameTypeDescription
vecReadonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>A vector.

Returns

number

The spherical angle phi of the vector.

Defined in

src/sdk/math/VecMath.ts:342


set

set(x, y, z, vec): Float64Array

Sets the components of a vector.

Parameters

NameTypeDescription
xnumberThe new x-component.
ynumberThe new y-component.
znumberThe new z-component.
vecFloat64ArrayThe vector to change.

Returns

Float64Array

The vector after it has been changed.

Defined in

src/sdk/math/VecMath.ts:354


setFromSpherical

setFromSpherical(r, theta, phi, vec): Float64Array

Sets the spherical components of a vector.

Parameters

NameTypeDescription
rnumberThe new length (magnitude).
thetanumberThe new spherical angle theta (polar angle), in radians.
phinumberThe new spherical angle phi (azimuthal angle), in radians.
vecFloat64ArrayThe vector to change.

Returns

Float64Array

The vector after it has been changed.

Defined in

src/sdk/math/VecMath.ts:369


sub

sub(v1, v2, out): Float64Array

Subtracts one vector from another.

Parameters

NameTypeDescription
v1Readonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>The first vector.
v2Readonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>The second vector.
outFloat64ArrayThe vector to write the results to.

Returns

Float64Array

the vector difference.

Defined in

src/sdk/math/VecMath.ts:399


theta

theta(vec): number

Gets the spherical angle theta (polar angle) of a vector in radians.

Parameters

NameTypeDescription
vecReadonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>A vector.

Returns

number

The spherical angle theta of the vector.

Defined in

src/sdk/math/VecMath.ts:333