Class: Vec2Math
Defined in: src/sdk/math/VecMath.ts:9
2D vector mathematical operations.
Constructors
Constructor
new Vec2Math():
Vec2Math
Returns
Vec2Math
Methods
abs()
static
abs(v1
):number
Defined in: src/sdk/math/VecMath.ts:134
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()
static
add(v1
,v2
,out
):Float64Array
Defined in: src/sdk/math/VecMath.ts:74
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.
copy()
static
copy(from
,to
):Float64Array
Defined in: src/sdk/math/VecMath.ts:209
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
static
create():Float64Array
Defined in: src/sdk/math/VecMath.ts:14
Creates a 2D vector initialized to [0, 0]
.
Returns
Float64Array
A new 2D vector initialized to [0, 0]
.
Call Signature
static
create(x
,y
):Float64Array
Defined in: src/sdk/math/VecMath.ts:21
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()
static
det(v1
,v2
):number
Defined in: src/sdk/math/VecMath.ts:111
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()
static
distance(vec1
,vec2
):number
Defined in: src/sdk/math/VecMath.ts:180
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()
static
dot(v1
,v2
):number
Defined in: src/sdk/math/VecMath.ts:101
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()
static
equals(vec1
,vec2
):boolean
Defined in: src/sdk/math/VecMath.ts:190
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()
static
isFinite(vec
):boolean
Defined in: src/sdk/math/VecMath.ts:199
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()
static
multScalar(v1
,scalar
,out
):Float64Array
Defined in: src/sdk/math/VecMath.ts:122
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()
static
normal(v1
,out
,counterClockwise
):Float64Array
Defined in: src/sdk/math/VecMath.ts:159
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()
static
normalize(v1
,out
):Float64Array
Defined in: src/sdk/math/VecMath.ts:144
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()
static
pointWithinPolygon(polygon
,point
):undefined
|boolean
Defined in: src/sdk/math/VecMath.ts:220
Checks if a point is within a polygon.
Parameters
Parameter | Type | Description |
---|---|---|
polygon | Readonly <Omit <Float64Array , "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()
static
set(x
,y
,vec
):Float64Array
Defined in: src/sdk/math/VecMath.ts:48
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()
static
setFromPolar(r
,theta
,vec
):Float64Array
Defined in: src/sdk/math/VecMath.ts:61
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()
static
sub(v1
,v2
,out
):Float64Array
Defined in: src/sdk/math/VecMath.ts:88
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()
static
theta(vec
):number
Defined in: src/sdk/math/VecMath.ts:37
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.