Matter.Vector
The Matter.Vector
module contains methods for creating and manipulating vectors.
Vectors are the basis of all the geometry related operations in the engine.
A Matter.Vector
object is of the form { x: 0, y: 0 }
.
See the included usage examples.
Methods
Matter.Vector.add
Adds the two vectors.
Returns
A new vector of vectorA and vectorB added
Matter.Vector.angle
Returns the angle between the vector vectorB - vectorA
and the x-axis in radians.
Returns
The angle in radians
Matter.Vector.clone
Returns a new vector with x
and y
copied from the given vector
.
Parameters
-
vector
Vector
Returns
A new cloned vector
Matter.Vector.cross
Returns the cross-product of two vectors.
Returns
The cross product of the two vectors
Matter.Vector.cross3
Returns the cross-product of three vectors.
Returns
The cross product of the three vectors
Matter.Vector.div
Divides a vector and a scalar.
Returns
A new vector divided by scalar
Matter.Vector.dot
Returns the dot-product of two vectors.
Returns
The dot product of the two vectors
Matter.Vector.magnitude
Returns the magnitude (length) of a vector.
Parameters
-
vector
Vector
Returns
The magnitude of the vector
Matter.Vector.magnitudeSquared
Returns the magnitude (length) of a vector (therefore saving a sqrt
operation).
Parameters
-
vector
Vector
Returns
The squared magnitude of the vector
Matter.Vector.mult
Multiplies a vector and a scalar.
Returns
A new vector multiplied by scalar
Matter.Vector.neg
Negates both components of a vector such that it points in the opposite direction.
Parameters
-
vector
Vector
Returns
The negated vector
Matter.Vector.normalise
Normalises a vector (such that its magnitude is 1
).
Parameters
-
vector
Vector
Returns
A new vector normalised
Matter.Vector.perp
Returns the perpendicular vector. Set negate
to true for the perpendicular in the opposite direction.
Parameters
-
vector
Vector -
[negate=false]
Bool optional
Returns
The perpendicular vector
Matter.Vector.rotate
Rotates the vector about (0, 0) by specified angle.
Returns
The vector rotated about (0, 0)
Matter.Vector.rotateAbout
Rotates the vector about a specified point by specified angle.
Returns
A new vector rotated about the point
Properties / Options
The following properties if specified below are for objects created by Matter.Vector.create
and may be passed to it as options
.
Temporary vector pool (not thread-safe).