Show:
API

Matter.Bodies

The Matter.Bodies module contains factory methods for creating rigid body models with commonly used body configurations (such as rectangles, circles and other polygons).

See the included usage examples.

Methods

Matter.Bodies.circle

(x, y, radius, [options], [maxSides])
Body

Creates a new rigid body model with a circle hull. The options parameter is an object that specifies any properties you wish to override the defaults. See the properties section of the Matter.Body module for detailed information on what you can pass via the options object.

Parameters

Returns

Body

A new circle body

Matter.Bodies.fromVertices

(x, y, vertexSets, [options], [flagInternal=false], [removeCollinear=0.01], [minimumArea=10], [removeDuplicatePoints=0.01])
Body

Utility to create a compound body based on set(s) of vertices.

Note: To optionally enable automatic concave vertices decomposition the poly-decomp package must be first installed and provided see Common.setDecomp, otherwise the convex hull of each vertex set will be used.

The resulting vertices are reorientated about their centre of mass, and offset such that body.position corresponds to this point.

The resulting offset may be found if needed by subtracting body.bounds from the original input bounds. To later move the centre of mass see Body.setCentre.

Note that automatic conconcave decomposition results are not always optimal. For best results, simplify the input vertices as much as possible first. By default this function applies some addtional simplification to help.

Some outputs may also require further manual processing afterwards to be robust. In particular some parts may need to be overlapped to avoid collision gaps. Thin parts and sharp points should be avoided or removed where possible.

The options parameter object specifies any Matter.Body properties you wish to override the defaults.

See the properties section of the Matter.Body module for detailed information on what you can pass via the options object.

Parameters

  • x Number
  • y Number
  • vertexSets Array

    One or more arrays of vertex points e.g. [[{ x: 0, y: 0 }...], ...].

  • [options] Object optional

    The body options.

  • [flagInternal=false] Bool optional

    Optionally marks internal edges with isInternal.

  • [removeCollinear=0.01] Number optional

    Threshold when simplifying vertices along the same edge.

  • [minimumArea=10] Number optional

    Threshold when removing small parts.

  • [removeDuplicatePoints=0.01] Number optional

    Threshold when simplifying nearby vertices.

Returns

Matter.Bodies.polygon

(x, y, sides, radius, [options])
Body

Creates a new rigid body model with a regular polygon hull with the given number of sides. The options parameter is an object that specifies any properties you wish to override the defaults. See the properties section of the Matter.Body module for detailed information on what you can pass via the options object.

Parameters

Returns

Body

A new regular polygon body

Matter.Bodies.rectangle

(x, y, width, height, [options])
Body

Creates a new rigid body model with a rectangle hull. The options parameter is an object that specifies any properties you wish to override the defaults. See the properties section of the Matter.Body module for detailed information on what you can pass via the options object.

Parameters

Returns

Body

A new rectangle body

Matter.Bodies.trapezoid

(x, y, width, height, slope, [options])
Body

Creates a new rigid body model with a trapezoid hull. The slope is parameterised as a fraction of width and must be < 1 to form a valid trapezoid. The options parameter is an object that specifies any properties you wish to override the defaults. See the properties section of the Matter.Body module for detailed information on what you can pass via the options object.

Parameters

Returns

Body

A new trapezoid body