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}.

CompoundGeometry

Compound geometry assembled from fixed solid parts.

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)[源代码]#

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)[源代码]#

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

参数:

**kwargs -- shape parameters

Returns: Geometry of the object

step(state)[源代码]#

Transform geometry to the new state.

参数:

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

返回:

Transformed geometry.

返回类型:

shapely.geometry.base.BaseGeometry

get_init_Gh()[源代码]#

Generate initial G and h for convex object.

返回:

  • 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

返回类型:

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

get_Gh(**kwargs)[源代码]#

Generate convex constraint matrices for the current shape type.

参数:

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

返回:

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

返回类型:

tuple

get_polygon_Gh(vertices: numpy.ndarray | None = None)[源代码]#

Generate G and h for convex polygon.

参数:

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

返回:

  • G matrix: (N, 2)

  • h vector: (N, 1)

  • cone_type (str): "Rpositive" for polygon

  • convex_flag (bool): whether convex constraints are valid

返回类型:

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

get_circle_Gh(center: numpy.ndarray, radius: float)[源代码]#

Generate G and h for circle.

参数:
  • center -- (2, 1) array of center

  • radius -- float of radius

返回:

  • G matrix: (3, 2)

  • h vector: (3, 1)

  • cone_type (str): "norm2"

  • convex_flag (bool): True

返回类型:

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

cal_length_width(geometry)[源代码]#

Calculate axis-aligned bounding-box length and width.

参数:

geometry -- Shapely geometry.

返回:

Length in x and width in y.

返回类型:

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.

返回:

The original centroid of the geometry.

返回类型:

np.ndarray

property radius#

Minimum bounding radius of the original geometry (cached per geometry).

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

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)[源代码]#

Construct a circle at the local origin.

参数:
  • 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.

返回:

Buffered point representing the circle.

返回类型:

shapely.geometry.Polygon

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

Bases: geometry_handler

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

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

Construct a polygon geometry.

参数:
  • 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()

返回:

Polygon object

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

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)[源代码]#

Construct a rectangle around the local origin.

参数:
  • length -- Rectangle length along x.

  • width -- Rectangle width along y.

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

返回:

Rectangle polygon.

返回类型:

shapely.geometry.Polygon

class irsim.lib.handler.geometry_handler.CompoundGeometry(name: str = 'compound', **kwargs)[源代码]#

Bases: geometry_handler

Compound geometry assembled from fixed solid parts.

Each part is defined in the owning object's body frame. Its optional pose is [x, y, theta] relative to that frame and defaults to the identity pose. The exact collision geometry is the union of all transformed parts, so overlapping parts do not introduce internal collision boundaries.

construct_original_geometry(parts: list[dict] | None = None, **kwargs)[源代码]#

Construct a compound geometry in the owning object's body frame.

参数:
  • parts -- Non-empty list of shape dictionaries. Each dictionary uses the existing primitive shape parameters and may include a local pose of [x, y, theta].

  • **kwargs -- Reserved for future compound-level options.

返回:

Union of all locally transformed part geometries.

返回类型:

shapely.geometry.Polygon | shapely.geometry.MultiPolygon

抛出:
  • ValueError -- If parts are missing, unsupported, empty, or have an invalid pose.

  • TypeError -- If a part is not a dictionary.

step(state)[源代码]#

Transform the compound and its individual parts to state.

property vertices: None#

A compound has no single exact vertex matrix.

property original_vertices: None#

A compound has no single exact original vertex matrix.

property part_vertices: list[numpy.ndarray]#

Current exterior vertices for each part as (2, N) arrays.

property original_part_vertices: list[numpy.ndarray]#

Body-frame exterior vertices for each part as (2, N) arrays.

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

Bases: geometry_handler

LineString geometry handler for wall or boundary segments.

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

Construct a LineString object.

参数:
  • 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()

返回:

LineString object

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

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)[源代码]#

Construct boundary lines around occupied map cells.

参数:
  • points -- (2, N) array of points

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

返回:

Boundary of occupied map cells.

返回类型:

shapely.geometry.MultiLineString

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

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)[源代码]#

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

step(state)[源代码]#

Transform geometry to the new state.

参数:

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

返回:

Transformed geometry.

class irsim.lib.handler.geometry_handler.GeometryFactory[源代码]#

Factory class to create geometry handlers.

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

Create a geometry handler from a YAML shape name.

参数:
  • name -- Shape name. Supported values are circle, polygon, rectangle, compound, linestring, and map.

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

返回:

Concrete geometry handler.

返回类型:

geometry_handler

抛出:

ValueError -- If name is not supported.