Skip to main content

Class: Vec2Math

2D vector mathematical operations.

Constructors

constructor

new Vec2Math(): Vec2Math

Returns

Vec2Math

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


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


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


create

create(): Float64Array

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

Returns

Float64Array

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

Defined in

src/sdk/math/VecMath.ts:14

create(x, y): Float64Array

Creates a 2D vector with specified x- and y- components.

Parameters

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

Returns

Float64Array

A new 2D vector with the specified components.

Defined in

src/sdk/math/VecMath.ts:21


det

det(v1, v2): number

Gets the determinant 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 determinant of the vectors.

Defined in

src/sdk/math/VecMath.ts:111


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


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


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


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


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


normal

normal(v1, out, counterClockwise?): Float64Array

Gets the normal of the supplied vector.

Parameters

NameTypeDefault valueDescription
v1Readonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>undefinedThe vector to get the normal for.
outFloat64ArrayundefinedThe vector to write the results to.
counterClockwisebooleanfalseWhether or not to get the counterclockwise normal.

Returns

Float64Array

the normal vector.

Defined in

src/sdk/math/VecMath.ts:159


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


pointWithinPolygon

pointWithinPolygon(polygon, point): undefined | boolean

Checks if a point is within a polygon.

Parameters

NameTypeDescription
polygonReadonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>[]The polygon to check against.
pointFloat64ArrayThe point to test.

Returns

undefined | boolean

True if the point is within or on the polygon, false otherwise.

Throws

An error if first and last points in a polygon are not the same.

Defined in

src/sdk/math/VecMath.ts:220


set

set(x, y, vec): Float64Array

Sets the components of a vector.

Parameters

NameTypeDescription
xnumberthe new x-component.
ynumberthe new y-component.
vecFloat64Arraythe vector to change.

Returns

Float64Array

the vector after it has been changed.

Defined in

src/sdk/math/VecMath.ts:48


setFromPolar

setFromPolar(r, theta, vec): Float64Array

Sets the polar components of a vector.

Parameters

NameTypeDescription
rnumberthe new length (magnitude).
thetanumberthe new polar angle theta, in radians.
vecFloat64Arraythe vector to change.

Returns

Float64Array

the vector after it has been changed.

Defined in

src/sdk/math/VecMath.ts:61


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


theta

theta(vec): number

Gets the polar angle theta of a vector in radians.

Parameters

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

Returns

number

the polar angle theta of the vector.

Defined in

src/sdk/math/VecMath.ts:37