Class: Vec2Math
2D vector mathematical operations.
Constructors
constructor
• new Vec2Math(): Vec2Math
Returns
Methods
abs
▸ abs(v1
): number
Gets the magnitude of a vector.
Parameters
Name | Type | Description |
---|---|---|
v1 | Readonly <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
Name | Type | Description |
---|---|---|
v1 | Readonly <Omit <Float64Array , "set" | "sort" | "copyWithin" >> | The first vector. |
v2 | Readonly <Omit <Float64Array , "set" | "sort" | "copyWithin" >> | The second vector. |
out | Float64Array | The 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
Name | Type | Description |
---|---|---|
from | Readonly <Omit <Float64Array , "set" | "sort" | "copyWithin" >> | The vector from which to copy. |
to | Float64Array | The 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
Name | 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.
Defined in
src/sdk/math/VecMath.ts:21
det
▸ det(v1
, v2
): number
Gets the determinant of two vectors.
Parameters
Name | Type | Description |
---|---|---|
v1 | Readonly <Omit <Float64Array , "set" | "sort" | "copyWithin" >> | The first vector. |
v2 | Readonly <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
Name | Type | Description |
---|---|---|
vec1 | Readonly <Omit <Float64Array , "set" | "sort" | "copyWithin" >> | The first vector. |
vec2 | Readonly <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
Name | Type | Description |
---|---|---|
v1 | Readonly <Omit <Float64Array , "set" | "sort" | "copyWithin" >> | The first vector. |
v2 | Readonly <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
Name | Type | Description |
---|---|---|
vec1 | Readonly <Omit <Float64Array , "set" | "sort" | "copyWithin" >> | The first vector. |
vec2 | Readonly <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
Name | Type | Description |
---|---|---|
vec | Readonly <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
Name | Type | Description |
---|---|---|
v1 | Readonly <Omit <Float64Array , "set" | "sort" | "copyWithin" >> | The vector to multiply. |
scalar | number | The scalar to apply. |
out | Float64Array | The 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
Name | Type | Default value | Description |
---|---|---|---|
v1 | Readonly <Omit <Float64Array , "set" | "sort" | "copyWithin" >> | 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.
Defined in
src/sdk/math/VecMath.ts:159
normalize
▸ normalize(v1
, out
): Float64Array
Normalizes the vector to a unit vector.
Parameters
Name | Type | Description |
---|---|---|
v1 | Readonly <Omit <Float64Array , "set" | "sort" | "copyWithin" >> | The vector to normalize. |
out | Float64Array | The 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
Name | 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.
Defined in
src/sdk/math/VecMath.ts:220
set
▸ set(x
, y
, vec
): Float64Array
Sets the components of a vector.
Parameters
Name | 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.
Defined in
src/sdk/math/VecMath.ts:48
setFromPolar
▸ setFromPolar(r
, theta
, vec
): Float64Array
Sets the polar components of a vector.
Parameters
Name | 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.
Defined in
src/sdk/math/VecMath.ts:61
sub
▸ sub(v1
, v2
, out
): Float64Array
Subtracts one vector from another.
Parameters
Name | Type | Description |
---|---|---|
v1 | Readonly <Omit <Float64Array , "set" | "sort" | "copyWithin" >> | The first vector. |
v2 | Readonly <Omit <Float64Array , "set" | "sort" | "copyWithin" >> | The second vector. |
out | Float64Array | The 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
Name | Type | Description |
---|---|---|
vec | Readonly <Omit <Float64Array , "set" | "sort" | "copyWithin" >> | a vector. |
Returns
number
the polar angle theta of the vector.
Defined in
src/sdk/math/VecMath.ts:37