Show:
API

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

(vectorA, vectorB, [output])
Vector

Adds the two vectors.

Parameters

Returns

Vector

A 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

Returns

Number

The angle in radians

Matter.Vector.clone

(vector)
Vector

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

Parameters

Returns

Vector

A new cloned vector

Matter.Vector.create

(x, y)
Vector

Creates a new vector.

Parameters

Returns

Vector

A new vector

Matter.Vector.cross

(vectorA, vectorB)
Number

Returns the cross-product of two vectors.

Parameters

Returns

Number

The cross product of the two vectors

Matter.Vector.cross3

(vectorA, vectorB, vectorC)
Number

Returns the cross-product of three vectors.

Parameters

Returns

Number

The cross product of the three vectors

Matter.Vector.div

(vector, scalar)
Vector

Divides a vector and a scalar.

Parameters

Returns

Vector

A new vector divided by scalar

Matter.Vector.dot

(vectorA, vectorB)
Number

Returns the dot-product of two vectors.

Parameters

Returns

Number

The dot product of the two vectors

Matter.Vector.magnitude

(vector)
Number

Returns the magnitude (length) of a vector.

Parameters

Returns

Number

The magnitude of the vector

Matter.Vector.magnitudeSquared

(vector)
Number

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

Parameters

Returns

Number

The squared magnitude of the vector

Matter.Vector.mult

(vector, scalar)
Vector

Multiplies a vector and a scalar.

Parameters

Returns

Vector

A 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

Returns

Vector

The negated vector

Matter.Vector.normalise

(vector)
Vector

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

Parameters

Returns

Vector

A 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] Bool optional

Returns

Vector

The perpendicular vector

Matter.Vector.rotate

(vector, angle, [output])
Vector

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

Parameters

Returns

Vector

The vector rotated about (0, 0)

Matter.Vector.rotateAbout

(vector, angle, point, [output])
Vector

Rotates the vector about a specified point by specified angle.

Parameters

Returns

Vector

A new vector rotated about the point

Matter.Vector.sub

(vectorA, vectorB, [output])
Vector

Subtracts the two vectors.

Parameters

Returns

Vector

A new vector of vectorA and vectorB subtracted

Properties / Options

The following properties are specified for objects created by Matter.Vector.create and may be passed to it as options.

private

Temporary vector pool (not thread-safe).

0.17.0