spatialgeometry.CollisionShapeGroup

class CollisionShapeGroup(initlist: Iterable[CollisionShape] | None = None, **kwargs)[source]

Bases: CollisionShape, UserList

An ordered, list-like collection of CollisionShape (or nested CollisionShapeGroup) 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 any SceneNode, a CollisionShapeGroup only accepts CollisionShape or CollisionShapeGroup instances – adding anything else (a plain Shape such as Axes, for instance) raises TypeError.

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 own iscollided()/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 CollisionShapeGroup has no single Coal collision geometry of its own – it is never itself passed to Coal, only iterated – so to_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, since iscollided()/closest_point() never touch self.co.

Every element’s scene_parent is kept pointing at the group, same as SceneGroup – adding an element (via the constructor, append, extend, insert, or item assignment) sets it, and removing one (remove, pop, clear, del) clears it back to None.

>>> 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 item to the end of the group and set its scene_parent to this group.

clear() None[source]

Remove every element from the group, clearing each one’s scene_parent.

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 to

  • inf_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 other to the end of the group, setting each one’s scene_parent to this group.

insert(i: int, item: CollisionShape) None[source]

Insert item at position i and set its scene_parent to 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 its scene_parent.

remove(item: CollisionShape) None[source]

Remove item from the group and clear its scene_parent.

to_dict() dict[str, Any][source]

to_dict() returns the shapes information in dictionary form

Returns:

All information about the shape

Return type:

dict