Methods
(static) clockWiseVec(a_x, a_y, b_x, b_y) → {boolean}
Check if second vector is on the right of first vector
Example
Math.clockWiseVec(0, 5, 5, 0);
//true
Parameters:
Name | Type | Description |
---|---|---|
a_x |
number | x position of first vector |
a_y |
number | y position of first vector |
b_x |
number | x position of second vector |
b_y |
number | y position of second vector |
Returns:
- Type
- boolean
(static) crossVec(a_x, a_y, b_x, b_y) → {number}
Calculate cross product of two vectors
Example
Math.crossVec(5, 0, 5, 5);
//25
Parameters:
Name | Type | Description |
---|---|---|
a_x |
number | x position of first vector |
a_y |
number | y position of first vector |
b_x |
number | x position of second vector |
b_y |
number | y position of second vector |
Returns:
- Type
- number
(static) dotVec(a_x, a_y, b_x, b_y) → {number}
Calculate dot product of two vectors
Example
Math.dotVec(5, 0, 5, 5);
//25
Parameters:
Name | Type | Description |
---|---|---|
a_x |
number | x position of first vector |
a_y |
number | y position of first vector |
b_x |
number | x position of second vector |
b_y |
number | y position of second vector |
Returns:
- Type
- number
(static) headVec(x, y) → {number}
Calculate angle of vector
Example
Math.headVec(5, 5);
//0.7853981633974483
Parameters:
Name | Type | Description |
---|---|---|
x |
number | x position |
y |
number | y position |
Returns:
Angle in radians
- Type
- number
(static) lerpVec(a_x, a_y, b_x, b_y, scale, returnDataopt) → {Object}
Interpolates from two vectors
Example
Math.lerpVec(5, 0, 5, 5, 0.5);
//{x: 5, y: 2.5}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
a_x |
number | x position of first vector | |
a_y |
number | y position of first vector | |
b_x |
number | x position of second vector | |
b_y |
number | y position of second vector | |
scale |
number | ||
returnData |
object |
<optional> |
Object to put data |
Returns:
- Type
- Object
(static) magVec(x, y, squareopt) → {number}
Calculate magnitude of vector
Example
Math.magVec(4, 0, true);
//4
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x |
number | x position | ||
y |
number | y position | ||
square |
boolean |
<optional> |
false
|
`false` if magnitude squared |
Returns:
- Type
- number
(static) normVec(x, y, returnDataopt) → {Object}
Normalize vector as scaling r to 1
Example
Math.normVec(2, 0);
//{x: 1, y: 0}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
number | x position | |
y |
number | y position | |
returnData |
object |
<optional> |
Object to put data |
Returns:
- Type
- Object
(static) perVec(x, y, returnDataopt) → {Object}
Calculate per product from vector
Example
Math.perVec(5, 0);
//{x1: -0, y1: 5, x2: 0, y2: -5}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
number | x position | |
y |
number | y position | |
returnData |
object |
<optional> |
Object to put data |
Returns:
- Type
- Object
(static) pol(x, y, returnDataopt) → {Object}
Convert cartesian to polar coordinates
Example
Math.pol(1, 0);
//{angle: 0, radial: 1}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
number | x position | |
y |
number | y position | |
returnData |
object |
<optional> |
Object to put data |
Returns:
- Type
- Object
(static) projVec(a_x, a_y, b_x, b_y, returnDataopt) → {Object}
Calculate projection vector from two vectors
Example
Math.projVec(5, 0, 5, 5);
//{x: 2.5, y: 2.5}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
a_x |
number | x position of first vector | |
a_y |
number | y position of first vector | |
b_x |
number | x position of second vector | |
b_y |
number | y position of second vector | |
returnData |
object |
<optional> |
Object to put data |
Returns:
- Type
- Object
(static) rec(x, y, radial, angle, returnDataopt) → {Object}
Convert polar to cartesian coordinates
Example
Math.rec(0, 0, 1, 0);
//{x: 1, y: 0}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
number | x position | |
y |
number | y position | |
radial |
number | r | |
angle |
number | angle | |
returnData |
object |
<optional> |
Object to put data |
Returns:
- Type
- Object
(static) rejVec(a_x, a_y, b_x, b_y, returnDataopt) → {Object}
Calculate rejection vector from two vectors
Example
Math.rejVec(5, 0, 5, 5);
//{x: 2.5, y: -2.5}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
a_x |
number | x position of first vector | |
a_y |
number | y position of first vector | |
b_x |
number | x position of second vector | |
b_y |
number | y position of second vector | |
returnData |
object |
<optional> |
Object to put data |
Returns:
- Type
- Object
(static) revVec(x, y, returnDataopt) → {Object}
Reverse vector
Example
Math.revVec(5, 0);
//{x: -5, y: 0}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
number | x position | |
y |
number | y position | |
returnData |
object |
<optional> |
Object to put data |
Returns:
- Type
- Object
(static) scaleVec(x, y, scale, returnDataopt) → {Object}
Scale vector
Example
Math.scaleVec(2, 0, 2);
//{x: 4, y: 0}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
number | x position | |
y |
number | y position | |
scale |
number | scale position | |
returnData |
object |
<optional> |
Object to put data |
Returns:
- Type
- Object
(static) truncVec(x, y, num, returnDataopt) → {Object}
Truncate vector to r = 1
Example
Math.truncVec(4, 0, 1);
//{x: 0.25, y: 0}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
number | x position | |
y |
number | y position | |
num |
number | truncate ratio | |
returnData |
object |
<optional> |
Object to put data |
Returns:
- Type
- Object
(static) wedgeVec(a_x, a_y, b_x, b_y) → {number}
Calculate wedge product of two vectors
Example
Math.wedgeVec(5, 0, 5, 5);
//25
Parameters:
Name | Type | Description |
---|---|---|
a_x |
number | x position of first vector |
a_y |
number | y position of first vector |
b_x |
number | x position of second vector |
b_y |
number | y position of second vector |
Returns:
- Type
- number