Constructor
new Vector(xopt, yopt, zopt)
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x |
number |
<optional> |
0
|
x component of the vector |
y |
number |
<optional> |
0
|
y component of the vector |
z |
number |
<optional> |
0
|
z component of the vector |
Members
x :number
- Source:
The x component of the vector
Type:
- number
y :number
- Source:
The y component of the vector
Type:
- number
z :number
- Source:
The z component of the vector
Type:
- number
Methods
add(x, yopt, zopt) → {Vector}
- Source:
Add a vector to this one, modifying this one.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
number | Vector | Array.<number> | the x component of the vector to be added. Alternatively, a Vector or list of numbers to add. | |
y |
number |
<optional> |
the y component of the vector to be added |
z |
number |
<optional> |
the z component of the vector to be added |
Returns:
this vector, modified
- Type
- Vector
angleBetween(vector) → {number}
- Source:
Find the angle between two vectors.
Parameters:
Name | Type | Description |
---|---|---|
vector |
Vector |
Returns:
angle in degrees
- Type
- number
array() → {Array.<number>}
- Source:
Returns the points of the vector as an array.
Returns:
values as an array
- Type
- Array.<number>
clone() → {Vector}
- Source:
Make a copy of this Vector.
Returns:
- Type
- Vector
copy() → {Vector}
- Source:
Make a copy of this Vector.
Returns:
- Type
- Vector
cross(v) → {Vector}
- Source:
Calculates a new Vector from the cross product of this vector and v.
Parameters:
Name | Type | Description |
---|---|---|
v |
Vector |
Returns:
- Type
- Vector
dot() → {number}
- Source:
Calculate the dot product of two vectors.
Returns:
dot product
- Type
- number
heading()
- Source:
Calculate the angle of rotation for this vector.
This only works for 2d vectors.
magnitude()
- Source:
Returns the magnitude of this vector.
multiply(x, yopt, zopt) → {Vector}
- Source:
Multiply this vector by a vector, scalar, or array, modifying it in place and returning it.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
number | Vector | Array.<number> | scalar to multiply the x component by Alternatively, a Vector or list of numbers to multiply | |
y |
number |
<optional> |
scalar to multiply the y component by |
z |
number |
<optional> |
scalar to multiply the z component by k |
Returns:
this vector, modified
- Type
- Vector
normalize() → {Vector}
- Source:
Normalizes a vector to length 1, making it a unit vector.
This is done by dividing each component of the vector by its magnitude.
Returns:
this vector
- Type
- Vector
rotate(angle) → {Vector}
- Source:
Rotates the vector by angle degrees.
Parameters:
Name | Type | Description |
---|---|---|
angle |
number | Rotation in degrees |
Returns:
this vector
- Type
- Vector
setHeading(heading)
- Source:
Set the heading of the vector.
Parameters:
Name | Type | Description |
---|---|---|
heading |
number | Heading in degrees |
subtract(x, yopt, zopt) → {Vector}
- Source:
Subtract a vector from this one, modifying this one.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
number | Vector | Array.<number> | the x component of the vector to be subtracted Alternatively, a Vector or list of numbers to substract. | |
y |
number |
<optional> |
the y component of the vector to be subtracted |
z |
number |
<optional> |
the z component of the vector to be subtracted |
Returns:
this vector, modified
- Type
- Vector