Skip to main content

Class: VecNMath

N-dimensional vector mathematical operations.

Constructors

constructor

new VecNMath(): VecNMath

Returns

VecNMath

Methods

abs

abs(vec): number

Gets the magnitude of a vector.

Parameters

NameTypeDescription
vecReadonly<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:561


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.

Throws

Error if the vectors are of unequal lengths.

Defined in

src/sdk/math/VecMath.ts:645


create

create(length): Float64Array

Creates an N-dimensional vector with all components initialized to 0.

Parameters

NameTypeDescription
lengthnumberThe length of the new vector.

Returns

Float64Array

A new N-dimensional vector with the specified length and all components initialized to 0.

Defined in

src/sdk/math/VecMath.ts:526

create(length, ...components): Float64Array

Creates an N-dimensional vector with specified components.

Parameters

NameTypeDescription
lengthnumberThe length of the new vector.
...componentsnumber[]The components of the new vector.

Returns

Float64Array

A new N-dimensional vector with the specified length and components.

Defined in

src/sdk/math/VecMath.ts:533


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.

Throws

Error if the two vectors are of unequal lengths.

Defined in

src/sdk/math/VecMath.ts:572


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:609


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:628


normalize

normalize(v1, out): Float64Array

Normalizes a 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:592


set

set(vec, ...components): Float64Array

Sets the components of a vector.

Parameters

NameTypeDescription
vecFloat64ArrayThe vector to change.
...componentsnumber[]The new components.

Returns

Float64Array

The vector after it has been changed.

Defined in

src/sdk/math/VecMath.ts:549