The Matter.Vertices module contains methods for creating and manipulating sets of vertices. A set of vertices is an array of Matter.Vector with additional indexing properties inserted by Vertices.create. A Matter.Body maintains a set of vertices to represent the shape of the object (its convex hull).

See the included usage examples.

Hierarchy

  • default

Constructors

Methods

  • Returns the area of the set of vertices.

    Parameters

    • vertices: IVector[]
    • Optional signed: boolean

    Returns number

    The area

    Method

    area

  • Chamfers a set of vertices by giving them rounded corners, returns a new set of vertices. The radius parameter is a single number or an array to specify the radius for each vertex.

    Type Parameters

    Parameters

    • vertices: T[]
    • radius: number | number[] = ...
    • quality: number = -1
    • qualityMin: number = 2
    • qualityMax: number = 14

    Returns T[]

    Method

    chamfer

  • Sorts the input vertices into clockwise order in place.

    Type Parameters

    Parameters

    • vertices: T[]

    Returns T[]

    vertices

    Method

    clockwiseSort

  • Returns true if the point is inside the set of vertices.

    Parameters

    Returns boolean

    True if the vertices contains point, otherwise false

    Method

    contains

  • Creates a new set of Matter.Body compatible vertices. The points argument accepts an array of Matter.Vector points orientated around the origin (0, 0), for example:

    [{ x: 0, y: 0 }, { x: 25, y: 50 }, { x: 50, y: 0 }]
    

    The Vertices.create method returns a new array of vertices, which are similar to Matter.Vector objects, but with some additional references required for efficient collision detection routines.

    Vertices must be specified in clockwise order.

    Note that the body argument is not optional, a Matter.Body reference must be provided.

    Parameters

    Returns IVertex[]

    Method

    create

  • Parses a string containing ordered x y pairs separated by spaces (and optionally commas), into a Matter.Vertices object for the given Matter.Body. For parsing SVG paths, see Svg.pathToVertices.

    Parameters

    • path: string
    • Optional body: IBody

    Returns IVertex[]

    vertices

    Method

    fromPath

  • Returns the convex hull of the input vertices as a new array of points.

    Type Parameters

    Parameters

    • vertices: T[]

    Returns T[]

    vertices

    Method

    hull

  • Returns the moment of inertia (second moment of area) of the set of vertices given the total mass.

    Parameters

    Returns number

    The polygon's moment of inertia

    Method

    inertia

  • Returns true if the vertices form a convex shape (vertices must be in clockwise order).

    Parameters

    Returns null | boolean

    true if the vertices are convex, false if not (or null if not computable).

    Method

    isConvex

  • Rotates the set of vertices in-place.

    Type Parameters

    Parameters

    • vertices: T[]
    • angle: number
    • point: IVector

    Returns void | T[]

    Method

    rotate

  • Scales the vertices from a point (default is centre) in-place.

    Type Parameters

    Parameters

    • vertices: T[]
    • scaleX: number
    • scaleY: number
    • point: IVector = ...

    Returns T[]

    Method

    scale

  • Translates the set of vertices in-place.

    Type Parameters

    Parameters

    • vertices: T[]
    • vector: IVector
    • scalar: number = 1

    Returns T[]

    Method

    translate

Generated using TypeDoc