Skip to main content

Class: PolygonShape

Defined in: physics/shapes/polygon-shape.ts:12

A convex polygon collision shape, defined by a set of local-space vertices. Vertices are re-centered around the polygon's centroid (so RigidBody.position represents the center of mass) and normalized to a consistent winding order.

Implements

Constructors

Constructor

new PolygonShape(vertices): PolygonShape

Defined in: physics/shapes/polygon-shape.ts:27

Creates a new PolygonShape instance.

Parameters

vertices

readonly Vector2[]

The local-space vertices of the polygon, in order. Must describe a convex polygon with at least 3 vertices. Vertices may be supplied in either winding order.

Returns

PolygonShape

Throws

An error if fewer than 3 vertices are provided, the vertices are collinear/degenerate, or the vertices do not form a convex polygon.

Properties

normals

readonly normals: readonly Vector2[]

Defined in: physics/shapes/polygon-shape.ts:17


type

readonly type: "polygon" = 'polygon'

Defined in: physics/shapes/polygon-shape.ts:13

The kind of shape this is, used to dispatch collision detection.

Implementation of

ShapeBase.type


vertices

readonly vertices: readonly Vector2[]

Defined in: physics/shapes/polygon-shape.ts:15

Methods

getArea()

getArea(): number

Defined in: physics/shapes/polygon-shape.ts:141

Calculates the area of the polygon.

Returns

number

The area of the polygon.

Implementation of

ShapeBase.getArea


getBoundingRadius()

getBoundingRadius(): number

Defined in: physics/shapes/polygon-shape.ts:172

Calculates the radius of the smallest circle, centered on the polygon's centroid, that fully contains the polygon.

Returns

number

The bounding radius of the polygon.

Implementation of

ShapeBase.getBoundingRadius


getMomentOfInertia()

getMomentOfInertia(mass): number

Defined in: physics/shapes/polygon-shape.ts:150

Calculates the moment of inertia of the polygon for a given mass.

Parameters

mass

number

The mass of the body the shape belongs to.

Returns

number

The moment of inertia of the polygon.

Implementation of

ShapeBase.getMomentOfInertia


getWorldNormals()

getWorldNormals(angle): Vector2[]

Defined in: physics/shapes/polygon-shape.ts:197

Transforms the polygon's local-space face normals into world space.

Parameters

angle

number

The world-space rotation of the body, in radians.

Returns

Vector2[]

The world-space face normals of the polygon.


getWorldVertices()

getWorldVertices(position, angle): Vector2[]

Defined in: physics/shapes/polygon-shape.ts:188

Transforms the polygon's local-space vertices into world space.

Parameters

position

Vector2

The world-space position of the body.

angle

number

The world-space rotation of the body, in radians.

Returns

Vector2[]

The world-space vertices of the polygon.


rectangle()

static rectangle(width, height): PolygonShape

Defined in: physics/shapes/polygon-shape.ts:61

Creates a rectangular PolygonShape centered on its local origin.

Parameters

width

number

The width of the rectangle.

height

number

The height of the rectangle.

Returns

PolygonShape

A new PolygonShape representing the rectangle.