Class: Vec2Math
Defined in: src/sdk/math/VecMath.ts:11
2D vector mathematical operations.
Constructors
Constructor
new Vec2Math():
Vec2Math
Returns
Vec2Math
Methods
abs()
staticabs(v1):number
Defined in: src/sdk/math/VecMath.ts:136
Gets the magnitude of a vector.
Parameters
| Parameter | Type | Description |
|---|---|---|
v1 | ReadonlyFloat64Array | The vector to get the magnitude for. |
Returns
number
the vector's magnitude.
add()
staticadd(v1,v2,out):Float64Array
Defined in: src/sdk/math/VecMath.ts:76
Add one vector to another.
Parameters
| Parameter | Type | Description |
|---|---|---|
v1 | ReadonlyFloat64Array | The first vector. |
v2 | ReadonlyFloat64Array | The second vector. |
out | Float64Array | The vector to write the results to. |
Returns
Float64Array
the vector sum.
angle()
staticangle(vec1,vec2):number
Defined in: src/sdk/math/VecMath.ts:193
Gets the angle between two vectors, in radians.
Parameters
| Parameter | Type | Description |
|---|---|---|
vec1 | ReadonlyFloat64Array | The first vector. |
vec2 | ReadonlyFloat64Array | The second vector. |
Returns
number
The angle between the two specified unit vectors, in radians, or NaN if either of the vectors has a
magnitude equal to zero.
copy()
staticcopy(from,to):Float64Array
Defined in: src/sdk/math/VecMath.ts:238
Copies one vector to another.
Parameters
| Parameter | Type | Description |
|---|---|---|
from | ReadonlyFloat64Array | The vector from which to copy. |
to | Float64Array | The vector to which to copy. |
Returns
Float64Array
The changed vector.
create()
Call Signature
staticcreate():Float64Array
Defined in: src/sdk/math/VecMath.ts:16
Creates a 2D vector initialized to [0, 0].
Returns
Float64Array
A new 2D vector initialized to [0, 0].
Call Signature
staticcreate(x,y):Float64Array
Defined in: src/sdk/math/VecMath.ts:23
Creates a 2D vector with specified x- and y- components.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | number | The x-component of the new vector. |
y | number | The y-component of the new vector. |
Returns
Float64Array
A new 2D vector with the specified components.
det()
staticdet(v1,v2):number
Defined in: src/sdk/math/VecMath.ts:113
Gets the determinant of two vectors.
Parameters
| Parameter | Type | Description |
|---|---|---|
v1 | ReadonlyFloat64Array | The first vector. |
v2 | ReadonlyFloat64Array | The second vector. |
Returns
number
The determinant of the vectors.
distance()
staticdistance(vec1,vec2):number
Defined in: src/sdk/math/VecMath.ts:182
Gets the Euclidean distance between two vectors.
Parameters
| Parameter | Type | Description |
|---|---|---|
vec1 | ReadonlyFloat64Array | The first vector. |
vec2 | ReadonlyFloat64Array | The second vector. |
Returns
number
the Euclidean distance between the two vectors.
dot()
staticdot(v1,v2):number
Defined in: src/sdk/math/VecMath.ts:103
Gets the dot product of two vectors.
Parameters
| Parameter | Type | Description |
|---|---|---|
v1 | ReadonlyFloat64Array | The first vector. |
v2 | ReadonlyFloat64Array | The second vector. |
Returns
number
The dot product of the vectors.
equals()
staticequals(vec1,vec2):boolean
Defined in: src/sdk/math/VecMath.ts:219
Checks if two vectors are equal.
Parameters
| Parameter | Type | Description |
|---|---|---|
vec1 | ReadonlyFloat64Array | The first vector. |
vec2 | ReadonlyFloat64Array | The second vector. |
Returns
boolean
Whether the two vectors are equal.
isFinite()
staticisFinite(vec):boolean
Defined in: src/sdk/math/VecMath.ts:228
Checks if a vector is finite. A vector is considered finite if all of its components are finite.
Parameters
| Parameter | Type | Description |
|---|---|---|
vec | ReadonlyFloat64Array | The vector to check. |
Returns
boolean
Whether the specified vector is finite.
multScalar()
staticmultScalar(v1,scalar,out):Float64Array
Defined in: src/sdk/math/VecMath.ts:124
Multiplies a vector by a scalar.
Parameters
| Parameter | Type | Description |
|---|---|---|
v1 | ReadonlyFloat64Array | The vector to multiply. |
scalar | number | The scalar to apply. |
out | Float64Array | The vector to write the results to. |
Returns
Float64Array
The scaled vector.
normal()
staticnormal(v1,out,counterClockwise):Float64Array
Defined in: src/sdk/math/VecMath.ts:161
Gets the normal of the supplied vector.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
v1 | ReadonlyFloat64Array | undefined | The vector to get the normal for. |
out | Float64Array | undefined | The vector to write the results to. |
counterClockwise | boolean | false | Whether or not to get the counterclockwise normal. |
Returns
Float64Array
the normal vector.
normalize()
staticnormalize(v1,out):Float64Array
Defined in: src/sdk/math/VecMath.ts:146
Normalizes the vector to a unit vector.
Parameters
| Parameter | Type | Description |
|---|---|---|
v1 | ReadonlyFloat64Array | The vector to normalize. |
out | Float64Array | The vector to write the results to. |
Returns
Float64Array
the normalized vector.
pointWithinPolygon()
staticpointWithinPolygon(polygon,point):undefined|boolean
Defined in: src/sdk/math/VecMath.ts:249
Checks if a point is within a polygon.
Parameters
| Parameter | Type | Description |
|---|---|---|
polygon | Readonly<Omit<Float64Array<ArrayBufferLike>, "set" | "sort" | "copyWithin">>[] | The polygon to check against. |
point | Float64Array | The 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.
set()
staticset(x,y,vec):Float64Array
Defined in: src/sdk/math/VecMath.ts:50
Sets the components of a vector.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | number | the new x-component. |
y | number | the new y-component. |
vec | Float64Array | the vector to change. |
Returns
Float64Array
the vector after it has been changed.
setFromPolar()
staticsetFromPolar(r,theta,vec):Float64Array
Defined in: src/sdk/math/VecMath.ts:63
Sets the polar components of a vector.
Parameters
| Parameter | Type | Description |
|---|---|---|
r | number | the new length (magnitude). |
theta | number | the new polar angle theta, in radians. |
vec | Float64Array | the vector to change. |
Returns
Float64Array
the vector after it has been changed.
sub()
staticsub(v1,v2,out):Float64Array
Defined in: src/sdk/math/VecMath.ts:90
Subtracts one vector from another.
Parameters
| Parameter | Type | Description |
|---|---|---|
v1 | ReadonlyFloat64Array | The first vector. |
v2 | ReadonlyFloat64Array | The second vector. |
out | Float64Array | The vector to write the results to. |
Returns
Float64Array
the vector difference.
theta()
statictheta(vec):number
Defined in: src/sdk/math/VecMath.ts:39
Gets the polar angle theta of a vector in radians.
Parameters
| Parameter | Type | Description |
|---|---|---|
vec | ReadonlyFloat64Array | a vector. |
Returns
number
the polar angle theta of the vector.
unitAngle()
staticunitAngle(vec1,vec2):number
Defined in: src/sdk/math/VecMath.ts:209
Gets the angle between two unit vectors, in radians.
Parameters
| Parameter | Type | Description |
|---|---|---|
vec1 | ReadonlyFloat64Array | The first unit vector. |
vec2 | ReadonlyFloat64Array | The second unit vector. |
Returns
number
The angle between the two specified unit vectors, in radians.