irsim.lib.handler.geometry_handler#
Classes#
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. |
|
Circular geometry handler for |
|
Polygon geometry handler for |
|
Rectangle geometry handler for |
|
Compound geometry assembled from fixed solid parts. |
|
LineString geometry handler for wall or boundary segments. |
|
Map-cell geometry handler that converts occupied points to line segments. |
|
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. |
|
Factory class to create geometry handlers. |
Module Contents#
- class irsim.lib.handler.geometry_handler.geometry_handler(name: str, **kwargs)[源代码]#
Bases:
abc.ABCThis 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, orradius. If omitted, callers should useget_init_Gh()for constraints from the original geometry.- 返回:
(G, h, cone_type, convex_flag)where unavailable constraints are returned asNonevalues.- 返回类型:
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_handlerCircular 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_handlerPolygon 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_handlerRectangle 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_handlerCompound geometry assembled from fixed solid parts.
Each part is defined in the owning object's body frame. Its optional
poseis[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
poseof[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.
- 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_handlerLineString 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_handlerMap-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.ABCThis 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#
- 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
shapename.- 参数:
name -- Shape name. Supported values are
circle,polygon,rectangle,compound,linestring, andmap.**kwargs -- Shape-specific parameters forwarded to the handler.
- 返回:
Concrete geometry handler.
- 返回类型:
- 抛出:
ValueError -- If
nameis not supported.