Module: utils/vectors
Functions
applyRotation
โธ applyRotation(base
, origin
, rotation
): vec2
[]
Rotates each vector in an array by a rotation angle in radians around an origin point.
Parameters
Name | Type | Description |
---|---|---|
base | vec2 [] | The vectors to apply the rotation to |
origin | vec2 | The origin to rotate the vectors around |
rotation | number | The rotation (in radians) to apply to each vector |
Returns
vec2
[]
The rotated vectors
Defined in
src/utils/vectors.ts:11
applyTranslation
โธ applyTranslation(base
, translation
): vec2
[]
Translates each vector in an array by a given translation vector
Parameters
Name | Type | Description |
---|---|---|
base | vec2 [] | The vectors to apply the translation to |
translation | vec2 | The translation to apply to each vector |
Returns
vec2
[]
The translated vectors
Defined in
src/utils/vectors.ts:27
cross2D
โธ cross2D(a
, b
): number
Calculates the cross product of 2 2D vectors and returns the Z value of the resulting 3D vector.
Parameters
Name | Type | Description |
---|---|---|
a | vec2 | The vector to cross |
b | vec2 | The vector to cross with a |
Returns
number
The Z coordinate of the resultant 3D vector
Defined in
src/utils/vectors.ts:89
cross2DWithScalar
โธ cross2DWithScalar(out
, a
, scalar
): vec2
Calculates the cross product of a with a scalar and stores the value in out
Parameters
Name | Type | Description |
---|---|---|
out | vec2 | The vector to output to |
a | vec2 | The vector to cross |
scalar | number | The scalar to cross a with |
Returns
vec2
out
Defined in
src/utils/vectors.ts:76
midpoint
โธ midpoint(out
, a
, b
): vec2
Calculate the midpoint between two vectors.
Parameters
Name | Type | Description |
---|---|---|
out | vec2 | The vector to output the result to |
a | vec2 | The start vector |
b | vec2 | The end vector |
Returns
vec2
The resultant vector, out
Defined in
src/utils/vectors.ts:101
tripleProduct
โธ tripleProduct(out
, a
, b
, c
): vec2
Calculates the triple product of three 2D vectors.
This is done by:
- extending each 2D vector into 3D by giving them a Z value of 0.
- Calculating the cross product of A and B, storing the result as vector Rโ. Rโ will be a vector purely in the z axis as the x and y components after the cross product are 0.
- The cross product of Rโ and C is then calculated, we'll call this Rโ. Rโ will be a vector that is perpendicular to C and pointing in the direction of B.
see
This post for an explanation
Parameters
Name | Type | Description |
---|---|---|
out | vec2 | - |
a | vec2 | Initial vector |
b | vec2 | Vector that the result will be in direction of |
c | vec2 | Vector that the result will be perpendicular to |
Returns
vec2
Defined in
src/utils/vectors.ts:55
vec2SloppyEquals
โธ vec2SloppyEquals(a
, b
, xSlop
, ySlop
): boolean
Determines wether two vectors are roughly equal to each other.
Parameters
Name | Type | Description |
---|---|---|
a | vec2 | The first vector |
b | vec2 | The second vector |
xSlop | number | The allowed x slop |
ySlop | number | The allowed y slop |
Returns
boolean
Wether the vectors are equal or not
Defined in
src/utils/vectors.ts:116