new Vector(x, yopt, zopt)
This class defines a multi-dimensional vector object and a variety of methods for manipulating the vector.
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
x |
number
|
The x coordinate. |
|
y |
number
|
<optional> |
The y coordinate. |
z |
number
|
<optional> |
The z coordinate. |
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
number
|
Array
|
Vector
|
The x coordinate or an array or Vector describing the whole vector. |
|
y |
number
|
<optional> |
The y coordinate. |
z |
number
|
<optional> |
The z coordinate. |
Members
Methods
(static) assign(object, propertyName, coordinateName*opt)
Adds properties to an object that describe the coordinates of a vector.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
object |
Object
|
Object on which the coordinates and vector will be added. |
|
propertyName |
String
|
A string describing the property name where the vector is accessable. |
|
coordinateName* |
String
|
<optional> |
One or more parameters describing coordinate values on the object. |
(static) recycle(vector)
Returns a Vector back to the cache. Prefer the Vector's recycle method since it recycles property objects as well.
Parameters:
Name | Type | Description |
---|---|---|
vector |
platypus.Vector
|
The Vector to be recycled. |
(static) setUp() → {platypus.Vector}
Returns a Vector from cache or creates a new one if none are available.
add(x, yopt, zopt)
Adds the given components to this vector.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
number
|
Array
|
Vector
|
The x component to add, or an array or vector describing the whole addition. |
|
y |
number
|
<optional> |
The y component to add or the limit if the first parameter is a vector or array. |
z |
number
|
<optional> |
The z component to add. |
addVector(otherVector)
Adds the given vector to this vector.
Parameters:
Name | Type | Description |
---|---|---|
otherVector |
platypus.Vector
|
The vector to add. |
angleTo(otherVector) → {number}
Finds the shortest angle between the two vectors.
Parameters:
Name | Type | Description |
---|---|---|
otherVector |
platypus.Vector
|
The other vector. |
Returns:
- Type:
-
number
The angle between this vector and the received vector.
copy() → {platypus.Vector}
Returns a copy of this vector.
cross(vector)
Crosses this vector with the parameter vector.
Parameters:
Name | Type | Description |
---|---|---|
vector |
platypus.Vector
|
The vector to cross this vector with. |
dot(otherVector, limit) → {number}
Finds the dot product of the two vectors.
Parameters:
Name | Type | Description |
---|---|---|
otherVector |
platypus.Vector
|
The other vector. |
limit |
number
|
The number of vector indexes to include in the dot product. |
Returns:
- Type:
-
number
The dot product.
equals(x, yopt, zopt) → {Boolean}
Determines whether two vectors are equal.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
number
|
Array
|
Vector
|
The x coordinate or an array or Vector to check against. |
|
y |
number
|
<optional> |
The y coordinate, or if x is an array/Vector this is the number of dimensions to check from the array/Vector. |
z |
number
|
<optional> |
The z coordinate. |
Returns:
- Type:
-
Boolean
Whether the vectors are equal.
getAngle() → {number}
Returns the direction of the vector from the z-axis
Returns:
- Type:
-
number
The direction of the vector in radians.
getCrossProduct(vector) → {platypus.Vector}
Crosses this vector with the parameter vector and returns the cross product.
Parameters:
Name | Type | Description |
---|---|---|
vector |
platypus.Vector
|
The vector to cross this vector with. |
getInverse() → {platypus.Vector}
Returns a copy of the Vector inverted.
Returns:
- Type:
-
platypus.Vector
getUnit() → {platypus.Vector}
Returns a normalized copy of the vector.
magnitude(dimensionsopt) → {number}
Returns the magnitude of the vector.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
dimensions |
number
|
<optional> |
The dimensions to include. Defaults to all dimensions. |
Returns:
- Type:
-
number
The magnitude of the vector.
magnitudeSquared(dimensionsopt) → {number}
Returns the magnitude squared of the vector. This is slightly faster than finding the magnitude.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
dimensions |
number
|
<optional> |
The dimensions to include. Defaults to all dimensions. |
Returns:
- Type:
-
number
The magnitude squared of the vector.
multiply(multiplier, limit)
Scales the vector by the given factor or performs a transform if a matrix is provided.
Parameters:
Name | Type | Description |
---|---|---|
multiplier |
number
|
Array
|
The factor to scale by or a 2D array describing a multiplication matrix. |
limit |
number
|
For scaling, determines which coordinates are affected. |
multiply(factor, limit)
Scales the vector by the given factor.
Parameters:
Name | Type | Description |
---|---|---|
factor |
number
|
The factor to scale by. |
limit |
number
|
Determines which coordinates are affected. Defaults to all coordinates. |
perpendicular(opposite)
Returns the perpendicular vector.
Parameters:
Name | Type | Description |
---|---|---|
opposite |
Boolean
|
Whether to negate the perpendicular vector. |
rotate(angle, axisopt)
Rotates the vector by the given amount.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
angle |
number
|
The amount to rotate the vector in radians. |
||
axis |
String
|
Vector
|
<optional> |
"z" |
A vector describing the axis around which the rotation should occur or 'x', 'y', or 'z'. |
rotateAbout(point, angle)
Rotates the vector position around a given point on the cartesian plane.
Parameters:
Name | Type | Description |
---|---|---|
point |
Vector
|
A vector describing the point around which the rotation should occur. |
angle |
number
|
The amount to rotate the vector in radians. |
scalerProjection(vectorOrAngle) → {number}
Find the scalar value of projecting this vector onto the parameter vector or onto a vector at the specified angle away.
Parameters:
Name | Type | Description |
---|---|---|
vectorOrAngle |
Vector
|
number
|
The other vector or the angle between the vectors. |
Returns:
- Type:
-
number
The magnitude of the projection.
set(x, yopt, zopt)
Sets the coordinates of the vector.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
number
|
Array
|
Vector
|
The x coordinate or an array or Vector describing the whole vector. |
|
y |
number
|
<optional> |
The y coordinate, or if x is an array/Vector this is the number of elements to copy from the array/Vector. |
z |
number
|
<optional> |
The z coordinate. |
setArray(arr, dimensionsopt)
Sets the coordinates of the vector.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
arr |
Array
|
The array to copy. |
|
dimensions |
number
|
<optional> |
The number of elements to copy from the Array. |
setVector(vector, dimensionsopt)
Sets the coordinates of the vector.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
vector |
Vector
|
The Vector to copy. |
|
dimensions |
number
|
<optional> |
The number of elements to copy from the Vector. |
setXYZ(x, yopt, zopt)
Sets the coordinates of the vector.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
number
|
The x coordinate. |
|
y |
number
|
<optional> |
The y coordinate. |
z |
number
|
<optional> |
The z coordinate. |
signedAngleTo(otherVector, normal) → {number}
Finds the shortest signed angle between the two vectors.
Parameters:
Name | Type | Description |
---|---|---|
otherVector |
platypus.Vector
|
The other vector. |
normal |
platypus.Vector
|
A normal vector determining the resultant sign of the angle between two vectors. |
Returns:
- Type:
-
number
The angle between this vector and the received vector.
subtractVector(otherVector)
Subtracts the given vector from this vector.
Parameters:
Name | Type | Description |
---|---|---|
otherVector |
platypus.Vector
|
The vector to subtract. |