Show:

# 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

(vectorA, vectorB, [output])

#### Parameters

• `vectorA` Vector
• `vectorB` Vector
• `[output]` Vector optional

#### Returns

Vector

A new vector of vectorA and vectorB added

### Matter.Vector.angle

(vectorA, vectorB)

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

Number

### Matter.Vector.clone

(vector)

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

#### Returns

Vector

A new cloned vector

### Matter.Vector.create

(x, y)

Creates a new vector.

Vector

A new vector

### Matter.Vector.cross

(vectorA, vectorB)

Returns the cross-product of two vectors.

#### Returns

Number

The cross product of the two vectors

### Matter.Vector.cross3

(vectorA, vectorB, vectorC)

Returns the cross-product of three vectors.

#### Returns

Number

The cross product of the three vectors

### Matter.Vector.div

(vector, scalar)

Divides a vector and a scalar.

#### Returns

Vector

A new vector divided by scalar

### Matter.Vector.dot

(vectorA, vectorB)

Returns the dot-product of two vectors.

#### Returns

Number

The dot product of the two vectors

### Matter.Vector.magnitude

(vector)

Returns the magnitude (length) of a vector.

#### Returns

Number

The magnitude of the vector

### Matter.Vector.magnitudeSquared

(vector)

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

#### Returns

Number

The squared magnitude of the vector

### Matter.Vector.mult

(vector, scalar)

Multiplies a vector and a scalar.

#### Returns

Vector

A new vector multiplied by scalar

### Matter.Vector.neg

(vector)

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

#### Returns

Vector

The negated vector

### Matter.Vector.normalise

(vector)

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

#### Returns

Vector

A new vector normalised

### Matter.Vector.perp

(vector, [negate=false])

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

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

#### Parameters

• `vector` Vector
• `angle` Number
• `[output]` Vector optional

#### Returns

Vector

The vector rotated about (0, 0)

(vector, angle, point, [output])

Rotates the vector about a specified point by specified angle.

#### Parameters

• `vector` Vector
• `angle` Number
• `point` Vector
• `[output]` Vector optional

#### Returns

Vector

A new vector rotated about the point

### Matter.Vector.sub

(vectorA, vectorB, [output])

Subtracts the two vectors.

#### Parameters

• `vectorA` Vector
• `vectorB` Vector
• `[output]` Vector optional

#### Returns

Vector

A new vector of vectorA and vectorB subtracted

## Item Index

### 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[]
private