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 |
|
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)[source]#
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)[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, orradius. If omitted, callers should useget_init_Gh()for constraints from the original geometry.- Returns:
(G, h, cone_type, convex_flag)where unavailable constraints are returned asNonevalues.- 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_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)[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_handlerPolygon 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_handlerRectangle 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_handlerLineString 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_handlerMap-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.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[source]#
Factory class to create geometry handlers.
- static create_geometry(name: str = 'circle', **kwargs) geometry_handler[source]#
Create a geometry handler from a YAML
shapename.- Parameters:
name β Shape name. Supported values are
circle,polygon,rectangle,linestring, andmap.**kwargs β Shape-specific parameters forwarded to the handler.
- Returns:
Concrete geometry handler.
- Return type:
- Raises:
ValueError β If
nameis not supported.