Class b2PolygonShape

Convex polygon. The vertices must be in CCW order for a right-handed coordinate system with the z-axis coming out of the screen.

Hierarchy

Index

Constructor methods

Methods

Constructor methods

constructor(): b2Shape

Creates a new b2Shape.

Returns

b2Shape

Methods

public static AsArray(vertices: b2Vec2[], vertexCount?: number): b2PolygonShape

Creates a b2PolygonShape from a vertices list. This assumes the vertices define a convex polygon. It is assumed that the exterior is the the right of each edge.

Parameters

  • vertices: b2Vec2[]

    List of vertices to create the polygon shape from.

  • vertexCount?: number optional

    Number of vertices in the shape, default value is 0 and in the box2dweb.js code it is ignored.

Returns

b2PolygonShape

Convex polygon shape.

public static AsBox(hx: number, hy: number): b2PolygonShape

Build vertices to represent an axis-aligned box.

Parameters

  • hx: number

    The half-width.

  • hy: number

    The half-height.

Returns

b2PolygonShape

Box polygon shape.

public static AsEdge(v1: b2Vec2, b2: b2Vec2): b2PolygonShape

Creates a single edge from two vertices.

Parameters

Returns

b2PolygonShape

Edge polygon shape.

public static AsOrientedBox(hx: number, hy: number, center?: b2Vec2, angle?: number): b2PolygonShape

Build vertices to represent an oriented box.

Parameters

  • hx: number

    The half-width.

  • hy: number

    The half-height.

  • center?: b2Vec2 optional

    The center of the box in local coordinates, default is null (no center?)

  • angle?: number optional

    The rotation of the box in local coordinates, default is 0.0.

Returns

b2PolygonShape

Oriented box shape.

public static AsVector(vertices: b2Vec2[], vertexCount?: number): b2PolygonShape

This assumes the vertices define a convex polygon. It is assumed that the exterior is the the right of each edge.

Parameters

  • vertices: b2Vec2[]

    List of vertices to create the polygon shape from.

  • vertexCount?: number optional

    The number of vertices, default is 0 and in the box2dweb.js code it is ignored.

Returns

b2PolygonShape

Convex polygon shape.

public ComputeAABB(aabb: b2AABB, xf: b2Transform)

Given a transform, compute the associated axis aligned bounding box for this shape.

Parameters

  • aabb: b2AABB

    Calculated AABB, this argument is out.

  • xf: b2Transform

    Transform to calculate the AABB.

public ComputeMass(massData: b2MassData, density: number)

Compute the mass properties of this shape using its dimensions and density. The inertia tensor is computed about the local origin, not the centroid.

Parameters

  • massData: b2MassData

    Calculate the mass, this argument is out.

  • density: number

public ComputeSubmergedArea(normal: b2Vec2, offset: number, xf: b2Transform, c: b2Vec2): number

Compute the volume and centroid of this shape intersected with a half plane

Parameters

  • normal: b2Vec2

    The surface normal.

  • offset: number

    The surface offset along the normal.

  • xf: b2Transform

    The shape transform.

  • c: b2Vec2

    The centroid, this argument is out.

Returns

number

public Copy(): b2PolygonShape

Clone the shape.

Returns

b2PolygonShape

public GetNormals(): b2Vec2[]

Get the edge normal vectors. There is one for each vertex.

Returns

b2Vec2[]

List of edge normal vectors for each vertex.

public GetSupport(d: b2Vec2): number

Get the supporting vertex index in the given direction.

Parameters

  • d: b2Vec2

    Direction to look.

Returns

number

Vertex index supporting the direction.

public GetSupportVertex(d: b2Vec2): b2Vec2

Get the supporting vertex in the given direction.

Parameters

  • d: b2Vec2

    Direciton to look.

Returns

b2Vec2

Vertex supporting the direction.

public GetType(): number

Get the type of this shape. You can use this to down cast to the concrete shape.

Returns

number

public GetVertexCount(): number

Get the vertex count.

Returns

number

Vertex count.

public GetVertices(): b2Vec2[]

Get the vertices in local coordinates.

Returns

b2Vec2[]

List of the vertices in local coordinates.

public RayCast(output: b2RayCastOutput, input: b2RayCastInput, transform: b2Transform): boolean

Cast a ray against this shape.

Parameters

Returns

boolean

True if the ray hits the shape, otherwise false.

public Set(other: b2Shape)

Set the shape values from another shape.

Parameters

  • other: b2Shape

    The other shape to copy values from.

public SetAsArray(vertices: b2Vec2[], vertexCount?: number)

Copy vertices. This assumes the vertices define a convex polygon. It is assumed that the exterior is the the right of each edge.

Parameters

  • vertices: b2Vec2[]

    List of vertices to create the polygon shape from.

  • vertexCount?: number optional

    Number of vertices in the shape, default value is 0 and in the box2dweb.js code it is ignored.

public SetAsBox(hx: number, hy: number)

Build vertices to represent an axis-aligned box.

Parameters

  • hx: number

    The half-width.

  • hy: number

    The half-height.

public SetAsEdge(v1: b2Vec2, b2: b2Vec2)

Creates a single edge from two vertices.

Parameters

public SetAsOrientedBox(hx: number, hy: number, center?: b2Vec2, angle?: number)

Build vertices to represent an oriented box.

Parameters

  • hx: number

    The half-width.

  • hy: number

    The half-height.

  • center?: b2Vec2 optional

    The center of the box in local coordinates, default is null (no center?)

  • angle?: number optional

    The rotation of the box in local coordinates, default is 0.0.

public SetAsVector(vertices: Array<any>, vertexCount?: number)

This assumes the vertices define a convex polygon. It is assumed that the exterior is the the right of each edge.

Parameters

  • vertices: Array<any>

    List of vertices to create the polygon shape from.

  • vertexCount?: number optional

    The number of vertices, default is 0 and in the box2dweb.js code it is ignored.

public TestPoint(xf: b2Transform, p: b2Vec2): boolean

Test a point for containment in this shape. This only works for convex shapes.

Parameters

  • xf: b2Transform

    Shape world transform.

  • p: b2Vec2

    Point to test against, in world coordinates.

Returns

boolean

True if the point is in this shape, otherwise false.