Constructor
new Vector(x, y)
Parameters:
Name | Type | Description |
---|---|---|
x |
number | |
y |
number |
- Version:
- v1.0.0
Methods
static dist(v1, v2) → {number}
get distance from two vectors
Parameters:
Name | Type | Description |
---|---|---|
v1 |
Vector | |
v2 |
Vector |
number
static distSq(v1, v2) → {number}
get distance squared from two vectors
Parameters:
Name | Type | Description |
---|---|---|
v1 |
Vector | |
v2 |
Vector |
number
static fromAngle(angle)
create vector from angle
Parameters:
Name | Type | Description |
---|---|---|
angle |
number |
static sub(v1, v2) → {Vector}
subtract two vectors
Parameters:
Name | Type | Description |
---|---|---|
v1 |
Vector | |
v2 |
Vector |
add(x, y) → {Vector}
add this vector to another vector
Parameters:
Name | Type | Description |
---|---|---|
x |
Vector | number | |
y |
Number |
angle(v) → {number}
get the angle thia and given vector
Parameters:
Name | Type | Description |
---|---|---|
v |
Vector |
number
array() → {Array}
return an array representation of this vector
Array
dist(v) → {number}
get distance between this and specific vector
Parameters:
Name | Type | Description |
---|---|---|
v |
Vector |
number
distSq(v) → {number}
get distance sqr between this and specific vector
Parameters:
Name | Type | Description |
---|---|---|
v |
Vector |
number
div(v) → {Vector}
divide this vector to a scalar value or a vector
Parameters:
Name | Type | Description |
---|---|---|
v |
Vector | number |
jitter(a, b) → {Vector}
adds random jitter motion
Parameters:
Name | Type | Description |
---|---|---|
a |
number | |
b |
number |
mult(v) → {Vector}
multiply this vector to a scalar value or a vector
Parameters:
Name | Type | Description |
---|---|---|
v |
Vector | number |
normalizeTo(length) → {Vector}
normalize this vector to a specific length
Parameters:
Name | Type | Description |
---|---|---|
length |
number |
rotate(a)
rotate this vector
Parameters:
Name | Type | Description |
---|---|---|
a |
number |
rotateBy(origin, theta) → {Vector}
rotate this vector by some origin and angle
Parameters:
Name | Type | Description |
---|---|---|
origin |
Vector | |
theta |
theta |
setAngle(angle)
set this vectors angle
Parameters:
Name | Type | Description |
---|---|---|
angle |
number |
setMag(value) → {Vector}
set the magnitude of this vector
Parameters:
Name | Type | Description |
---|---|---|
value |
number |
sub(x, y) → {Vector}
subtracts this vector to another vector
Parameters:
Name | Type | Description |
---|---|---|
x |
Vector | number | |
y |
Number |
toString() → {String}
return a string representation of this vector
String