Class b2PolygonShape
A solid convex polygon of 3 to 16 vertices in counter-clockwise order, with the polygon skin radius. Setting vertices builds their convex hull (gift wrapping), so collinear and interior points are dropped and the order may change.
public sealed class b2PolygonShape : b2Shape
- Inheritance
-
b2PolygonShape
- Inherited Members
- Extension Methods
Remarks
Reference: Box2D/Collision/Shapes/b2PolygonShape.cpp.
Constructors
b2PolygonShape()
An empty polygon with the polygon skin radius; set its vertices before use.
public b2PolygonShape()
b2PolygonShape(IReadOnlyList<b2Vec2>?, (double hx, double hy)?)
A polygon from pybox2d's keyword arguments: polygonShape(vertices=...) or polygonShape(box=(hx, hy)).
A failure carries pybox2d's Failed on kwargs for b2PolygonShape.vertices: (or .box) prefix.
public b2PolygonShape(IReadOnlyList<b2Vec2>? vertices, (double hx, double hy)? box = null)
Parameters
verticesIReadOnlyList<b2Vec2>The vertices, or null.
box(double hx, double hy)?The half-extents of an axis-aligned box centered on the origin, applied after
vertices.
Remarks
Python applies keyword arguments in call order; here vertices always goes first, which only
matters when both are given and both fail.
Exceptions
- ValueError
Thrown for a vertex count outside 2..16.
- AssertionError
Thrown for fewer than 3 vertices, a degenerate edge, or no area.
- OverflowError
Thrown for a half-extent beyond the float32 range.
Properties
Box
Makes the polygon an axis-aligned box of the given half-extents (pybox2d's write-only box).
public (double hx, double hy) Box { set; }
Property Value
Exceptions
- OverflowError
Thrown for a half-extent beyond the float32 range.
Centroid
The centroid (pybox2d's centroid).
public b2Vec2 Centroid { get; }
Property Value
Normals
The edge normals (pybox2d's normals).
public IReadOnlyList<b2Vec2> Normals { get; }
Property Value
VertexCount
The number of vertices (pybox2d's vertexCount).
public int VertexCount { get; }
Property Value
Vertices
The vertices (pybox2d's vertices), counter-clockwise from the hull's right-most lowest point. Setting them
stores each one, then builds the convex hull, normals and centroid (Box2D's Set); an empty list clears them.
public IReadOnlyList<b2Vec2> Vertices { get; set; }
Property Value
Exceptions
- ValueError
Thrown by the setter for a count outside 2..16, with pybox2d's message.
- AssertionError
Thrown by the setter for fewer than 3 vertices, a degenerate edge, or no area.
Methods
SetAsBox(double, double, b2Vec2, double)
Makes the polygon an oriented box (pybox2d's box = (hx, hy, center, angle)).
public void SetAsBox(double hx, double hy, b2Vec2 center, double angle)
Parameters
hxdoubleThe half-width.
hydoubleThe half-height.
centerb2Vec2The box's center in local coordinates.
angledoubleThe box's rotation in radians.
Exceptions
- OverflowError
Thrown for a scalar beyond the float32 range.