- Matter.Vertices
- Methods
- Matter.Vertices.area
- Matter.Vertices.centre
- Matter.Vertices.chamfer
- Matter.Vertices.clockwiseSort
- Matter.Vertices.contains
- Matter.Vertices.create
- Matter.Vertices.fromPath
- Matter.Vertices.hull
- Matter.Vertices.inertia
- Matter.Vertices.isConvex
- Matter.Vertices.mean
- Matter.Vertices.rotate
- Matter.Vertices.scale
- Matter.Vertices.translate
- Item Index
- Methods
Matter.Vertices
Defined in: src/geometry/Vertices.js:1
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.
Methods
Matter.Vertices.area
(vertices, signed)
→ Number
Returns the area of the set of vertices.
Parameters
vertices
Vertices
signed
Bool
Returns
NumberThe area
@ src/geometry/Vertices.js:116
Matter.Vertices.centre
(vertices)
→ Vector
Returns the centre (centroid) of the set of vertices.
Parameters
vertices
Vertices
Returns
VectorThe centre point
Matter.Vertices.chamfer
(vertices, radius, quality, qualityMin, qualityMax)
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.
Parameters
vertices
Vertices
radius
Number[]
quality
Number
qualityMin
Number
qualityMax
Number
@ src/geometry/Vertices.js:260
Matter.Vertices.clockwiseSort
(vertices)
→ Vertices
Sorts the input vertices into clockwise order in place.
Parameters
vertices
Vertices
Returns
Verticesvertices
@ src/geometry/Vertices.js:334
Matter.Vertices.contains
(vertices, point)
→ Boolean
Returns true
if the point
is inside the set of vertices
.
Parameters
vertices
Vertices
point
Vector
Returns
BooleanTrue if the vertices contains point, otherwise false
@ src/geometry/Vertices.js:214
Matter.Vertices.create
(points, body)
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
points
Vector[]
body
Body
Matter.Vertices.fromPath
(path, body)
→ Vertices
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
body
Body
Returns
Verticesvertices
Matter.Vertices.hull
(vertices)
→
Returns the convex hull of the input vertices as a new array of points.
Parameters
vertices
Vertices
Returns
[vertex] vertices
@ src/geometry/Vertices.js:394
Matter.Vertices.inertia
(vertices, mass)
→ Number
Returns the moment of inertia (second moment of area) of the set of vertices given the total mass.
Parameters
vertices
Vertices
mass
Number
Returns
NumberThe polygon's moment of inertia
@ src/geometry/Vertices.js:138
Matter.Vertices.isConvex
(vertices)
→ Bool
Returns true if the vertices form a convex shape (vertices must be in clockwise order).
Parameters
vertices
Vertices
Returns
Booltrue
if the vertices
are convex, false
if not (or null
if not computable).
@ src/geometry/Vertices.js:350
Matter.Vertices.mean
(vertices)
→ Vector
Returns the average (mean) of the set of vertices.
Parameters
vertices
Vertices
Returns
VectorThe average point
Matter.Vertices.rotate
(vertices, angle, point)
Rotates the set of vertices in-place.
Parameters
vertices
Vertices
angle
Number
point
Vector
@ src/geometry/Vertices.js:188
Matter.Vertices.scale
(vertices, scaleX, scaleY, point)
Scales the vertices from a point (default is centre) in-place.
Parameters
vertices
Vertices
scaleX
Number
scaleY
Number
point
Vector
@ src/geometry/Vertices.js:233
Matter.Vertices.translate
(vertices, vector, scalar)
Translates the set of vertices in-place.
Parameters
vertices
Vertices
vector
Vector
scalar
Number
@ src/geometry/Vertices.js:164