group

A group is a collection of objects that can be manipulated together. Unlike a compound, the constituent objects of a group retain their individual identities and can be moved, rotated, or otherwise altered individually. Group is more expensive computationally than compound.

Objects are added to a group by specifying group=mygroup when the object is created.

mygroup = group()
Parameters:
  • pos (vector) – Position of the group. Default vec(0,0,0). Moving pos moves all objects in the group.

  • axis (vector) – Orientation of the group. Default vec(1,0,0). Changing axis rotates all objects in the group.

  • up (vector) – A vector perpendicular to the axis. Setting up sets up for all objects in the group.

  • color (vector) – Setting color sets the color of all objects in the group.

  • visible (boolean) – If False, all objects in the group are hidden. Default True.

Example: create a group and add objects to it:

mygroup = group()
b = box( group=mygroup )
s = sphere( pos=vec(2,0,0), group=mygroup )
mygroup.pos = vec(1,0,0)  # moves both objects

Group and world coordinates

The pos of each object in a group is stored relative to the group’s pos (group coordinates). The group provides two conversion functions:

world_pos = mygroup.group_to_world( v ) converts a position in group coordinates to world coordinates.

group_pos = mygroup.world_to_group( v ) converts a position in world coordinates to group coordinates.

Rotating a group

All objects in a group can be rotated together:

mygroup.rotate( angle=a, axis=vec(0,1,0) )

The optional origin parameter specifies the center of rotation. Default is mygroup.pos.

Changing mygroup.axis also rotates all member objects.

Restrictions on groups

Labels cannot be members of a group. Objects must be assigned to a group at creation time using the group= parameter; objects cannot be added to or removed from a group after creation.

See also

canvas; color; compound; rotate;