Constructor
new Vector(xopt, yopt, zopt)
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x | number | <optional> | 0 | |
y | number | <optional> | 0 | |
z | number | <optional> | 0 |
- Source
Methods
add(vopt, yopt, zopt)
adds two vectors together
Name | Type | Attributes | Description |
---|---|---|---|
v | number | | <optional> | |
y | number | <optional> | |
z | number | <optional> |
- Source
- See
- Vector.from for parameters
array() → {Array.<number>}
returns the array form of the vector
- Source
- the array
- Type:
- Array.<number>
cross(vopt, yopt, zopt) → {Vector}
get the cross product of two vectors
Name | Type | Attributes | Description |
---|---|---|---|
v | number | | <optional> | |
y | number | <optional> | |
z | number | <optional> |
- Source
- See
- Vector.from for parameters
- the cross product
- Type:
- Vector
dist(vec) → {number}
gets the distance between two vectors
Name | Type | Description |
---|---|---|
vec | Vector | vector |
- Source
- the distance
- Type:
- number
div(vopt, yopt, zopt)
divide one vector from another
Name | Type | Attributes | Description |
---|---|---|---|
v | number | | <optional> | |
y | number | <optional> | |
z | number | <optional> |
- Source
- See
- Vector.from for parameters
dot(vopt, yopt, zopt) → {number}
get the dot product of two vectors
Name | Type | Attributes | Description |
---|---|---|---|
v | number | | <optional> | |
y | number | <optional> | |
z | number | <optional> |
- Source
- See
- Vector.from for parameters
- the dot product
- Type:
- number
get() → {Vector}
returns a new vector with the same (x, y, z) values
- Source
- copied vector
- Type:
- Vector
heading() → {number}
returns the angle of the vector only for 2D vectors
- Source
- angle
- Type:
- number
lerp(vopt, yopt, zopt)
lerps a vector toward another
Name | Type | Attributes | Description |
---|---|---|---|
v | number | | <optional> | |
y | number | <optional> | |
z | number | <optional> |
- Source
- See
- Vector.from for parameters
limit(len)
limit the length of a vector
Name | Type | Description |
---|---|---|
len | number | length |
- Source
mag() → {number}
returns the magnitude of the vector
- Source
- the magnitude
- Type:
- number
magSq() → {number}
returns the squared magnitude of the vector
- Source
- the squared magnitude
- Type:
- number
mult(vopt, yopt, zopt)
multiply two vectors together
Name | Type | Attributes | Description |
---|---|---|---|
v | number | | <optional> | |
y | number | <optional> | |
z | number | <optional> |
- Source
- See
- Vector.from for parameters
normalize()
normalizes a vector to length 1
- Source
object() → {Object}
returns the object form of the vector
- Source
- the object
- Type:
- Object
project(vopt, yopt, zopt) → {Vector}
xxx HS16 Projects the current vector onto another
Name | Type | Attributes | Description |
---|---|---|---|
v | number | | <optional> | |
y | number | <optional> | |
z | number | <optional> |
- Source
The projected vector
- Type:
- Vector
rotate(ang)
rotates a vector a certain angle for 2D vectors only
Name | Type | Description |
---|---|---|
ang | number | angle |
- Source
set(vopt, yopt, zopt)
sets the value of a vector
Name | Type | Attributes | Description |
---|---|---|---|
v | number | | <optional> | |
y | number | <optional> | |
z | number | <optional> |
- Source
- See
- Vector.from for parameters
setMag(vec, lenopt) → {Vector}
sets the magnitude of the vector
Name | Type | Attributes | Description |
---|---|---|---|
vec | number | | length or vector | |
len | number | <optional> | length |
- Source
- only if len is defined
- Type:
- Vector
sub(vopt, yopt, zopt)
subtracts one vector from another
Name | Type | Attributes | Description |
---|---|---|---|
v | number | | <optional> | |
y | number | <optional> | |
z | number | <optional> |
- Source
- See
- Vector.from for parameters
toString() → {string}
returns the string form of the vector
- Source
- the string of the vector coordinates
- Type:
- string
(static) angleBetween(vec1, vec2) → {number}
returns the angle between two vectors
- Source
- angle
- Type:
- number
(static) from(vopt, yopt, zopt) → {Vector}
takes any range of values an' makes 'em a vector. aka magic.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
v | number | | <optional> | if y, Vector, object, or array of values representing the vector; else, x coordinate. | |
y | number | <optional> | ||
z | number | <optional> | 0 |
- Source
- Type:
- Vector
(static) fromAngle(ang, vecopt) → {Vector}
creates a vector from an angle
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
ang | number | angle | ||
vec | Vector | <optional> | new Vector | vector |
- Source
- the vector
- Type:
- Vector
(static) random2D(vecopt) → {Vector}
creates a random 2D vector
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
vec | Vector | <optional> | new Vector | vector |
- Source
- the vector
- Type:
- Vector
(static) random3D(vecopt) → {Vector}
creates a random 3D vector
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
vec | Vector | <optional> | new Vector | vector |
- Source
- the vector
- Type:
- Vector