irsim.lib.handler.geometry_handler#

Classes#

geometry_handler

This class is used to handle the geometry of the object. It reads the shape parameters from yaml file and constructs the geometry of the object.

CircleGeometry

Circular geometry handler for shape: {name: circle}.

PolygonGeometry

Polygon geometry handler for shape: {name: polygon}.

RectangleGeometry

Rectangle geometry handler for shape: {name: rectangle}.

LinestringGeometry

LineString geometry handler for wall or boundary segments.

PointsGeometry

Map-cell geometry handler that converts occupied points to line segments.

geometry_handler3d

This class is used to handle the 3D geometry of the object. It reads the shape parameters from yaml file and constructs the geometry of the object.

GeometryFactory

Factory class to create geometry handlers.

Module Contents#

class irsim.lib.handler.geometry_handler.geometry_handler(name: str, **kwargs)[source]#

Bases: abc.ABC

This class is used to handle the geometry of the object. It reads the shape parameters from yaml file and constructs the geometry of the object.

name#
geometry#
wheelbase#
abstractmethod construct_original_geometry(**kwargs)[source]#

Construct the original geometry of the object when the state is in the origin of coordinates.

Parameters:

**kwargs – shape parameters

Returns: Geometry of the object

step(state)[source]#

Transform geometry to the new state.

Parameters:

state (np.ndarray) – State vector [x, y, theta].

Returns:

Transformed geometry.

Return type:

shapely.geometry.base.BaseGeometry

get_init_Gh()[source]#

Generate initial G and h for convex object.

Returns:

  • G matrix: (N, 2)

  • h vector: (N, 1)

  • cone_type (str): β€œnorm2” for circle or β€œRpositive” for polygon

  • convex_flag (bool): whether convex constraints are valid

Return type:

tuple[np.ndarray, np.ndarray, str | None, bool | None]

get_Gh(**kwargs)[source]#

Generate convex constraint matrices for the current shape type.

Parameters:

**kwargs – Shape-specific data such as vertices, center, or radius. If omitted, callers should use get_init_Gh() for constraints from the original geometry.

Returns:

(G, h, cone_type, convex_flag) where unavailable constraints are returned as None values.

Return type:

tuple

get_polygon_Gh(vertices: numpy.ndarray | None = None)[source]#

Generate G and h for convex polygon.

Parameters:

vertices – (2, N), N: Edge number of the object

Returns:

  • G matrix: (N, 2)

  • h vector: (N, 1)

  • cone_type (str): β€œRpositive” for polygon

  • convex_flag (bool): whether convex constraints are valid

Return type:

tuple[np.ndarray | None, np.ndarray | None, str | None, bool]

get_circle_Gh(center: numpy.ndarray, radius: float)[source]#

Generate G and h for circle.

Parameters:
  • center – (2, 1) array of center

  • radius – float of radius

Returns:

  • G matrix: (3, 2)

  • h vector: (3, 1)

  • cone_type (str): β€œnorm2”

  • convex_flag (bool): True

Return type:

tuple[np.ndarray, np.ndarray, str, bool]

cal_length_width(geometry)[source]#

Calculate axis-aligned bounding-box length and width.

Parameters:

geometry – Shapely geometry.

Returns:

Length in x and width in y.

Return type:

tuple[float, float]

property vertices#

Current geometry vertices as a (2, N) array.

property init_vertices#

[[x1, y1], [x2, y2]…. [[x1, y1]]]; [x1, y1] will repeat twice

Type:

return original_vertices

property original_vertices: numpy.ndarray | None#

Get the original vertices of the geometry.

property original_centroid: numpy.ndarray#

Get the original centroid of the geometry.

Returns:

The original centroid of the geometry.

Return type:

np.ndarray

property radius#

Minimum bounding radius of the original geometry.

class irsim.lib.handler.geometry_handler.CircleGeometry(name: str = 'circle', **kwargs)[source]#

Bases: geometry_handler

Circular geometry handler for shape: {name: circle}.

construct_original_geometry(radius: float = 0.2, center: list | None = None, random_shape: bool = False, radius_range: list | None = None, wheelbase: float | None = None)[source]#

Construct a circle at the local origin.

Parameters:
  • radius – Circle radius.

  • center – Local center [x, y].

  • random_shape – If True, sample radius from radius_range.

  • radius_range – [min, max] radius range for random shapes.

  • wheelbase – Optional Ackermann wheelbase offset for car-like bodies.

Returns:

Buffered point representing the circle.

Return type:

shapely.geometry.Polygon

class irsim.lib.handler.geometry_handler.PolygonGeometry(name: str = 'polygon', **kwargs)[source]#

Bases: geometry_handler

Polygon geometry handler for shape: {name: polygon}.

construct_original_geometry(vertices=None, random_shape: bool = False, is_convex: bool = False, **kwargs)[source]#

Construct a polygon geometry.

Parameters:
  • vertices – [[x1, y1], [x2, y2]..]

  • random_shape – whether to generate random shape, default is False

  • is_convex – whether to generate convex shape, default is False

  • **kwargs – see random_generate_polygon()

Returns:

Polygon object

class irsim.lib.handler.geometry_handler.RectangleGeometry(name: str = 'rectangle', **kwargs)[source]#

Bases: geometry_handler

Rectangle geometry handler for shape: {name: rectangle}.

construct_original_geometry(length: float = 1.0, width: float = 1.0, wheelbase: float | None = None)[source]#

Construct a rectangle around the local origin.

Parameters:
  • length – Rectangle length along x.

  • width – Rectangle width along y.

  • wheelbase – Optional Ackermann wheelbase used to offset the rear axle.

Returns:

Rectangle polygon.

Return type:

shapely.geometry.Polygon

class irsim.lib.handler.geometry_handler.LinestringGeometry(name: str = 'linestring', **kwargs)[source]#

Bases: geometry_handler

LineString geometry handler for wall or boundary segments.

construct_original_geometry(vertices, random_shape: bool = False, is_convex: bool = True, **kwargs)[source]#

Construct a LineString object.

Parameters:
  • vertices – [[x1, y1], [x2, y2]..]

  • random_shape – whether to generate random shape, default is False

  • is_convex – whether to generate convex shape, default is False

  • **kwargs – see random_generate_polygon()

Returns:

LineString object

class irsim.lib.handler.geometry_handler.PointsGeometry(name: str = 'map', **kwargs)[source]#

Bases: geometry_handler

Map-cell geometry handler that converts occupied points to line segments.

construct_original_geometry(points: numpy.ndarray, reso: numpy.ndarray | float = 0.1, **kwargs)[source]#

Construct boundary lines around occupied map cells.

Parameters:
  • points – (2, N) array of points

  • reso – resolution, either a (2, 1) array [x_reso, y_reso] or a scalar applied to both axes

Returns:

Boundary of occupied map cells.

Return type:

shapely.geometry.MultiLineString

class irsim.lib.handler.geometry_handler.geometry_handler3d(name: str, **kwargs)[source]#

Bases: abc.ABC

This class is used to handle the 3D geometry of the object. It reads the shape parameters from yaml file and constructs the geometry of the object.

name#
geometry#
wheelbase#
abstractmethod construct_original_geometry(**kwargs)[source]#

Construct the local-frame 3D geometry before any state transform.

step(state)[source]#

Transform geometry to the new state.

Parameters:

state (np.ndarray 6*1) – [x, y, z, roll, pitch, yaw].

Returns:

Transformed geometry.

class irsim.lib.handler.geometry_handler.GeometryFactory[source]#

Factory class to create geometry handlers.

static create_geometry(name: str = 'circle', **kwargs) geometry_handler[source]#

Create a geometry handler from a YAML shape name.

Parameters:
  • name – Shape name. Supported values are circle, polygon, rectangle, linestring, and map.

  • **kwargs – Shape-specific parameters forwarded to the handler.

Returns:

Concrete geometry handler.

Return type:

geometry_handler

Raises:

ValueError – If name is not supported.