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

Returns

VectorA new vector of vectorA and vectorB added

@ src/geometry/Vector.js:142

Matter.Vector.angle

(vectorA, vectorB)

Number

Returns the angle between the vector vectorB - vectorA and the x-axis in radians.

Parameters

Returns

NumberThe angle in radians

@ src/geometry/Vector.js:216

Matter.Vector.clone

(vector)

Vector

Returns a new vector with x and y copied from the given vector.

Parameters

Returns

VectorA new cloned vector

@ src/geometry/Vector.js:30

Matter.Vector.create

(x, y)

Vector

Creates a new vector.

Parameters

Returns

VectorA new vector

@ src/geometry/Vector.js:19

Matter.Vector.cross

(vectorA, vectorB)

Number

Returns the cross-product of two vectors.

Parameters

Returns

NumberThe cross product of the two vectors

@ src/geometry/Vector.js:119

Matter.Vector.cross3

(vectorA, vectorB, vectorC)

Number

Returns the cross-product of three vectors.

Parameters

Returns

NumberThe cross product of the three vectors

@ src/geometry/Vector.js:130

Matter.Vector.div

(vector, scalar)

Vector

Divides a vector and a scalar.

Parameters

Returns

VectorA new vector divided by scalar

@ src/geometry/Vector.js:183

Matter.Vector.dot

(vectorA, vectorB)

Number

Returns the dot-product of two vectors.

Parameters

Returns

NumberThe dot product of the two vectors

@ src/geometry/Vector.js:108

Matter.Vector.magnitude

(vector)

Number

Returns the magnitude (length) of a vector.

Parameters

Returns

NumberThe magnitude of the vector

@ src/geometry/Vector.js:40

Matter.Vector.magnitudeSquared

(vector)

Number

Returns the magnitude (length) of a vector (therefore saving a sqrt operation).

Parameters

Returns

NumberThe squared magnitude of the vector

@ src/geometry/Vector.js:50

Matter.Vector.mult

(vector, scalar)

Vector

Multiplies a vector and a scalar.

Parameters

Returns

VectorA new vector multiplied by scalar

@ src/geometry/Vector.js:172

Matter.Vector.neg

(vector)

Vector

Negates both components of a vector such that it points in the opposite direction.

Parameters

Returns

VectorThe negated vector

@ src/geometry/Vector.js:206

Matter.Vector.normalise

(vector)

Vector

Normalises a vector (such that its magnitude is 1).

Parameters

Returns

VectorA new vector normalised

@ src/geometry/Vector.js:95

Matter.Vector.perp

(vector, [negate=false])

Vector

Returns the perpendicular vector. Set negate to true for the perpendicular in the opposite direction.

Parameters

  • [negate=false] Booloptional

Returns

VectorThe perpendicular vector

@ src/geometry/Vector.js:194

Matter.Vector.rotate

(vector, angle, [output])

Vector

Rotates the vector about (0, 0) by specified angle.

Parameters

Returns

VectorThe vector rotated about (0, 0)

@ src/geometry/Vector.js:60

Matter.Vector.rotateAbout

(vector, angle, point, [output])

Vector

Rotates the vector about a specified point by specified angle.

Parameters

Returns

VectorA new vector rotated about the point

@ src/geometry/Vector.js:77

Matter.Vector.sub

(vectorA, vectorB, [output])

Vector

Subtracts the two vectors.

Parameters

Returns

VectorA new vector of vectorA and vectorB subtracted

@ src/geometry/Vector.js:157

Item Index

Methods

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).

@ src/geometry/Vector.js:227