spatialgeometry.CollisionShapeGroup
- class CollisionShapeGroup(initlist: Iterable[CollisionShape] | None = None, **kwargs)[source]
Bases:
CollisionShape,UserListAn ordered, list-like collection of
CollisionShape(or nestedCollisionShapeGroup) objects that itself behaves like a single collision-checkable shape.- Parameters:
initlist – Initial elements to populate the group with.
collision – Whether this group participates in collision checking, defaults to True.
Unlike
SceneGroup, which admits anySceneNode, aCollisionShapeGrouponly acceptsCollisionShapeorCollisionShapeGroupinstances – adding anything else (a plainShapesuch asAxes, for instance) raisesTypeError.iscollided()/closest_point()work in every combination of shape-vs-shape, shape-vs-group, group-vs-shape, and group-vs-group, including arbitrarily nested groups – a group checks each of its own elements in turn (delegating to that element’s owniscollided()/closest_point(), which handles the other side being a group itself if needed) and aggregates: any element collided means the group collided; the closest element’s own(d, p1, p2)is the group’s.A
CollisionShapeGrouphas no single Coal collision geometry of its own – it is never itself passed to Coal, only iterated – soto_dict()(there is no single dict that could describe a collection) and_init_coal()(there is no single geometry to build) both raise if called directly. Nothing in normal use calls either, sinceiscollided()/closest_point()never touchself.co.Every element’s
scene_parentis kept pointing at the group, same asSceneGroup– adding an element (via the constructor,append,extend,insert, or item assignment) sets it, and removing one (remove,pop,clear,del) clears it back toNone.>>> from spatialgeometry import CollisionShapeGroup, Cuboid, Sphere >>> from spatialmath import SE3 >>> group = CollisionShapeGroup() >>> group.append(Cuboid([1, 1, 1])) >>> group.append(Sphere(1, pose=SE3.Trans(3, 0, 0))) >>> len(group) 2
- Parameters:
pose – Local reference frame of the shape, defaults to the identity transform.
color – Color as (r, g, b) or (r, g, b, a) in [0-1] (or [0-255], auto-normalised), or a matplotlib color name. Defaults to a mid-grey
(0.3, 0.3, 0.3, 1.0).stype – Shape type identifier used by the renderer/wire protocol (e.g.
"cuboid","mesh") – set by each concrete subclass, not normally passed directly by a caller.base – Deprecated alias for
pose.
- append(item: CollisionShape) None[source]
Add
itemto the end of the group and set itsscene_parentto this group.
- closest_point(shape: CollisionShape, inf_dist: float = 1.0) tuple[float | None, ndarray | None, ndarray | None][source]
Return the minimum euclidean distance between this group and shape – the closest
(d, p1, p2)among this group’s own elements.- Parameters:
shape – The shape (or
CollisionShapeGroup) to compare distance toinf_dist – Only return a result when distance < inf_dist
- Returns:
(d, p1, p2) — distance and closest points in world frame, or (None, None, None) when every element is farther than inf_dist.
- property data: list[CollisionShape]
- extend(other: Iterable[CollisionShape]) None[source]
Add every element of
otherto the end of the group, setting each one’sscene_parentto this group.
- insert(i: int, item: CollisionShape) None[source]
Insert
itemat positioniand set itsscene_parentto this group.
- iscollided(shape: CollisionShape) bool[source]
Return True if any element of this group has collided with shape.
- Parameters:
shape – The shape (or
CollisionShapeGroup) to check against
- pop(i: int = -1) CollisionShape[source]
Remove and return the element at position
i(default: the last one), clearing itsscene_parent.
- remove(item: CollisionShape) None[source]
Remove
itemfrom the group and clear itsscene_parent.