Table of Contents

Class b2PolygonShape

Namespace
Gym.Box2D
Assembly
Gym.Environments.dll

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

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

vertices IReadOnlyList<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

(double From, double To)

Exceptions

OverflowError

Thrown for a half-extent beyond the float32 range.

Centroid

The centroid (pybox2d's centroid).

public b2Vec2 Centroid { get; }

Property Value

b2Vec2

Normals

The edge normals (pybox2d's normals).

public IReadOnlyList<b2Vec2> Normals { get; }

Property Value

IReadOnlyList<b2Vec2>

VertexCount

The number of vertices (pybox2d's vertexCount).

public int VertexCount { get; }

Property Value

int

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

IReadOnlyList<b2Vec2>

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

hx double

The half-width.

hy double

The half-height.

center b2Vec2

The box's center in local coordinates.

angle double

The box's rotation in radians.

Exceptions

OverflowError

Thrown for a scalar beyond the float32 range.