- Matter.Vector
- Methods
- Matter.Vector.add
- Matter.Vector.angle
- Matter.Vector.clone
- Matter.Vector.create
- Matter.Vector.cross
- Matter.Vector.cross3
- Matter.Vector.div
- Matter.Vector.dot
- Matter.Vector.magnitude
- Matter.Vector.magnitudeSquared
- Matter.Vector.mult
- Matter.Vector.neg
- Matter.Vector.normalise
- Matter.Vector.perp
- Matter.Vector.rotate
- Matter.Vector.rotateAbout
- Matter.Vector.sub
- Item Index
- Properties
- Methods
Matter.Vector
Defined in: src/geometry/Vector.js:1
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
(vectorA, vectorB, [output])
→ Vector
Adds the two vectors.
Parameters
vectorA
Vector
vectorB
Vector
[output]
Vectoroptional
Returns
VectorA new vector of vectorA and vectorB added
Matter.Vector.angle
(vectorA, vectorB)
→ Number
Returns the angle between the vector vectorB - vectorA
and the x-axis in radians.
Parameters
vectorA
Vector
vectorB
Vector
Returns
NumberThe angle in radians
Matter.Vector.clone
(vector)
→ Vector
Returns a new vector with x
and y
copied from the given vector
.
Parameters
vector
Vector
Returns
VectorA new cloned vector
Matter.Vector.create
(x, y)
→ Vector
Creates a new vector.
Parameters
x
Number
y
Number
Returns
VectorA new vector
Matter.Vector.cross
(vectorA, vectorB)
→ Number
Returns the cross-product of two vectors.
Parameters
vectorA
Vector
vectorB
Vector
Returns
NumberThe cross product of the two vectors
Matter.Vector.cross3
(vectorA, vectorB, vectorC)
→ Number
Returns the cross-product of three vectors.
Parameters
vectorA
Vector
vectorB
Vector
vectorC
Vector
Returns
NumberThe cross product of the three vectors
Matter.Vector.div
(vector, scalar)
→ Vector
Divides a vector and a scalar.
Parameters
vector
Vector
scalar
Number
Returns
VectorA new vector divided by scalar
Matter.Vector.dot
(vectorA, vectorB)
→ Number
Returns the dot-product of two vectors.
Parameters
vectorA
Vector
vectorB
Vector
Returns
NumberThe dot product of the two vectors
Matter.Vector.magnitude
(vector)
→ Number
Returns the magnitude (length) of a vector.
Parameters
vector
Vector
Returns
NumberThe magnitude of the vector
Matter.Vector.magnitudeSquared
(vector)
→ Number
Returns the magnitude (length) of a vector (therefore saving a sqrt
operation).
Parameters
vector
Vector
Returns
NumberThe squared magnitude of the vector
Matter.Vector.mult
(vector, scalar)
→ Vector
Multiplies a vector and a scalar.
Parameters
vector
Vector
scalar
Number
Returns
VectorA new vector multiplied by scalar
Matter.Vector.neg
(vector)
→ Vector
Negates both components of a vector such that it points in the opposite direction.
Parameters
vector
Vector
Returns
VectorThe negated vector
Matter.Vector.normalise
(vector)
→ Vector
Normalises a vector (such that its magnitude is 1
).
Parameters
vector
Vector
Returns
VectorA new vector normalised
Matter.Vector.perp
(vector, [negate=false])
→ Vector
Returns the perpendicular vector. Set negate
to true for the perpendicular in the opposite direction.
Parameters
vector
Vector
[negate=false]
Booloptional
Returns
VectorThe perpendicular vector
Matter.Vector.rotate
(vector, angle, [output])
→ Vector
Rotates the vector about (0, 0) by specified angle.
Parameters
vector
Vector
angle
Number
[output]
Vectoroptional
Returns
VectorThe vector rotated about (0, 0)
Matter.Vector.rotateAbout
(vector, angle, point, [output])
→ Vector
Rotates the vector about a specified point by specified angle.
Parameters
vector
Vector
angle
Number
point
Vector
[output]
Vectoroptional
Returns
VectorA new vector rotated about the point
Matter.Vector.sub
(vectorA, vectorB, [output])
→ Vector
Subtracts the two vectors.
Parameters
vectorA
Vector
vectorB
Vector
[output]
Vectoroptional
Returns
VectorA new vector of vectorA and vectorB subtracted
Item Index
Methods
- add
- angle
- clone
- create
- cross
- cross3
- div
- dot
- magnitude
- magnitudeSquared
- mult
- neg
- normalise
- perp
- rotate
- rotateAbout
- sub
Properties
The following properties are specified for objects created by <span class="prefix">Matter.</span>.create
and for objects passed to it via the options
argument.
Properties
The following properties are specified for objects created by Matter.Vector.create
and for objects passed to it via the options
argument.
Vector._temp
Vector[]private
Temporary vector pool (not thread-safe).