Category:Physics Engine/Polygon Shapes
Polygon shapes are bounded by a set of line segments. The enclosed area of the polygon must be convex and the vertices must be defined in counterclockwise order. Poygon shapes are of type TI.cpPolyShape.
PolyShape
ps = physics.PolyShape(body, vertices, offset)
Parameter | Type | Description |
---|---|---|
body | in physics.Body | A Body or nil |
vertices in {physics.Vect} | The list of vertices that define the boundaries of the polygon defined in counterclockwise order | |
offset | in physics.Vect | The offset of the PolyShape from the Body |
ps | out physics.PolyShape | A new PolyShape |
Returns a new PolyShape with the given body, table of vertices, and offset from the body's center of gravity. Specify nil for the body to use the space's static body.
Introduced in platform.apiLevel = '2.0'
numVerts
nv = physics.PolyShape:numVerts()
Parameter | Type | Description |
---|---|---|
self | in physics.PolyShape | The input PolyShape |
nv | out number | The number of vertices in the PolyShape |
Returns the number of vertices in the table of polygon vertices.
Introduced in platform.apiLevel = '2.0'
points
points = physics.PolyShape:points()
Parameter | Type | Description |
---|---|---|
self | in physics.PolyShape | The input PolyShape |
points out {physics.Vect} | A table of vertices that define the boundary of the polygon. The vertices are translated to the polygon's current world coordinates |
Returns a copy of the table of vertices defining the bounds of the polygon. The vertices are translated to the polygon's current world coordinates.
When a PolyShape has not been added to a Space, it has no world coordinates. In this case, each vertex returned by physics.PolyShape:points() will have x and y equal to 0.
NOTE |
Introduced in platform.apiLevel = '2.0'
vert
v = physics.PolyShape:vert(n)
Parameter | Type | Description |
---|---|---|
self | in physics.PolyShape | The input PolyShape |
v | out physics.Vect | The nth vertex of the polygon. The coordinates of the vector are relative to the shape's Body |
Returns vertex number n_ of the table of vertices defining the bounds of the polygon. If the shape is static then the vertex values are in world coordinates, otherwise the vertex coordiates are relative to the shape's body. Returns nil if _n is less than 1 or greater than the number of vertices in the polygon.
Introduced in platform.apiLevel = '2.0'
This category currently contains no pages or media.