blueprints.thing.moveable module#

class blueprints.thing.moveable.MoveableThing[source]#

Bases: MoveableThingType, BaseThing

This class enables Things to have a position in space and an orientation specified using (improper) euler angles. To place the same Thing in multiple positions and orientations four shortcut methods can be used to construct copies of the Thing on the fly. Those method manipulate position and orientation and this manipulation is either relative to the current position/orientation or absolute, overwriting the current position/orientation.

Relative manipulation:#
>>> thing = MoveableThing(pos=[0, 0, 1], alpha=0.8)
>>> shifted_thing = thing.shift([2, 0, 0])
>>> shifted_thing.pos
array([2., 0., 1.], dtype=float32)
>>> rotated_thing = thing.rotate(beta=0.3)
>>> rotated_thing.euler
array([0.8, 0.3, 0. ], dtype=float32)
Absolute manipulation:#
>>> located_thing = thing.locate([2, 0, 0])
>>> located_thing.pos
array([2., 0., 0.], dtype=float32)
>>> oriented_thing = thing.align(beta=0.3)
>>> oriented_thing.euler
array([0. , 0.3, 0. ], dtype=float32)
Size manipulation:#
>>> scaled_thing = thing.scaled(3)
>>> scaled_thing.pos
array([0., 0., 3.], dtype=float32)
>>> scaled_thing.size
array([1.5, 1.5, 1.5], dtype=float32)

For MoveableThing instances in a kinematic tree, position and orientation are locally defined, describing the relative change in position and rotation to their parents. If one wants to create relocated copies using shift() or locate() for global coordinates the globally argument can be set on call.

Relocation shortcuts also take other MoveableThing instances as arguments. This results in a change in position by the arguments position.

>>> thing_a = MoveableThing(pos=[0, 0, 1])
>>> thing_b = MoveableThing(pos=[0, 1, 0])
>>> thing_c = thing_a.shift(pos=thing_b)
>>> thing_c.pos
array([0., 1., 1.], dtype=float32)
__init__(pos=[0.0, 0.0, 0.0], alpha=0.0, beta=0.0, gamma=0.0, name=None, x=None, y=None, z=None, quat=None, **kwargs)[source]#

MoveableThing implements multiple Thing location and orientation in (improper) euler angles in radians.

Parameters:
  • pos (list[int | float] | np.ndarray | None, optional) – Represents the position of the object. Changing this attribute also changes the properties x, y and z.

  • alpha (int | float | None, optional) – (Improper) euler angle of rotation around the x-axis in radian. Changing this value also changes the euler property.

  • beta (int | float | None, optional) – (Improper) euler angle of rotation around the y-axis in radian. Changing this value also changes the euler property.

  • gamma (int | float | None, optional) – (Improper) euler angle of rotation around the z-axis in radian. Changing this value also changes the euler property.

  • name (str | None, optional) – The user specified name for the Thing.

  • x (int | float |np.int32 | np.int64 | np.float32 | np.float64 | None, optional) – If pos is not specified, this argument sets the X position coordinate.

  • y (int | float |np.int32 | np.int64 | np.float32 | np.float64 | None, optional) – If pos is not specified, this argument sets the Y position coordinate.

  • z (int | float |np.int32 | np.int64 | np.float32 | np.float64 | None, optional) – If pos is not specified, this argument sets the Z position coordinate.

  • quat (list [ int | float ] | np.ndarray | None, optional) – If set, the quaternion orientation overwrites the euler angles alpha, beta and gamma.

  • **kwargs – Keyword arguments are passed to super().__init__.

view()[source]#

This method creates a throw away World <blueprints.world.World>`, attaches itself to it and uses its viewer.

Return type:

None

lattice(directions, repetitions, name=None)[source]#

This method constructs a Lattice with the MoveableThing as its components.

Parameters:
  • directions (list [ float | int ] | np.ndarray | list [ list [ int | float ] ] | list [ np.ndarray ]) – A list of axes pointing into the directions of the Lattice.

  • repetitions (int | list [ int ] | np.ndarray) – A list of repetitions for each axis with the same length as directions

  • name (str | None) – The name of the Lattice (used for displaying purposes).

Returns:

A Lattice created with the MoveableThing as components

Return type:

blue.LatticeType

property rotation_matrix: ndarray#

The matrix is constructed for local orientation (w.r.t. to parent orientation) — in contrast to global orientation. For this use Rotation.global_orientation.

Returns:

The rotation matrix for the Thins orientation.

Return type:

np.ndarray

property global_rotation_matrix: ndarray#

The matrix is constructed for global orientation) — in contrast to local orientation. For this use Rotation.E_rot.

Returns:

The rotation matrix for the Thins orientation.

Return type:

np.ndarray

shift(pos=None, globally=False, x=None, y=None, z=None, **kwargs)[source]#

This method creates a copy that is shifted by pos.

>>> MoveableThing(pos=[5, 0, 0]).shift(x=-3, y=10).pos
array([2., 10., 0.], dtype=float32)
Parameters:
  • pos (list[int | float] | np.ndarray | blue.MoveableThingType | None) – The amount by which the Thing is shifted, optionally another MoveableThing can be passed in which case the position of this Thing is taken.

  • globally (bool, optional) – Determining whether the shift is relative to the local orientation or the global orientation.

  • x (int | float | np.int32 | np.int64 | np.float32 | np.float64 | None) – This argument can be set if just the X component of the position is to be changed.

  • y (int | float | np.int32 | np.int64 | np.float32 | np.float64 | None) – This argument can be set if just the Y component of the position is to be changed.

  • z (int | float | np.int32 | np.int64 | np.float32 | np.float64 | None) – This argument can be set if just the Z component of the position is to be changed.

  • **kwargs – Keyword arguments are passed to the copy().

Returns:

A shifted copy is returned.

Return type:

blue.MoveableThingType

locate(pos=None, globally=False, x=None, y=None, z=None, **kwargs)[source]#

This method creates a copy that is relocated to pos.

>>> MoveableThing(pos=[5, 0, 0]).locate(x=-3, y=10).pos
array([-3., 10., 0.], dtype=float32)
Parameters:
  • pos (list[int | float] | np.ndarray | blue.MoveableThingType | None) – The position to which the Thing is shifted, optionally another MoveableThing can be passed in which case the position of this Thing is taken.

  • globally (bool, optional) – Determining whether the relocation is relative to the local orientation or the global orientation.

  • x (int | float | np.int32 | np.int64 | np.float32 | np.float64 | None) – This argument can be set if just the X component of the position is to be changed.

  • y (int | float | np.int32 | np.int64 | np.float32 | np.float64 | None) – This argument can be set if just the Y component of the position is to be changed.

  • z (int | float | np.int32 | np.int64 | np.float32 | np.float64 | None) – This argument can be set if just the Z component of the position is to be changed.

  • **kwargs – Keyword arguments are passed to copy().

Returns:

A relocated copy is returned.

Return type:

blue.MoveableThingType

rotate(alpha=0, beta=0, gamma=0, quat=None, globally=True, center=None, **kwargs)[source]#

This method creates a copy that is rotated by the (improper) euler angles.

>>> MoveableThing(alpha=TAU/4, beta=0, gamma=TAU/8).rotate(beta=PI).euler
array([-TAU/4,  PI,  TAU/8], dtype=float32)
Parameters:
  • alpha (int | float, optional) – The (improer) euler angle of rotation around the X-axis in radians.

  • beta (int | float, optional) – The (improer) euler angle of rotation around the Y-axis in radians.

  • gamma (int | float, optional) – The (improer) euler angle of rotation around the Z-axis in radians.

  • globally (bool, optional) – Determining whether the rotation is relative to the local orientation or the global orientation.

  • center (list[int | float] | np.ndarray | blue.MoveableThingType | None, optional) – The copied Thing will be rotated around center. If center is None, it will be rotated at its position instead.

  • **kwargs – Keyword arguments are passed to the copy().

  • quat (list[int | float] | ndarray | None)

Returns:

A copy of the returned Thing is returned.

Return type:

blue.MoveableThingType

align(alpha=0.0, beta=0.0, gamma=0.0, quat=None, **kwargs)[source]#

This method creates a copy that is oriented according to the (improper) euler angles.

>>> MoveableThing(alpha=TAU/4, beta=0, gamma=TAU/8).align(beta=PI).euler
array([0,  PI,  0], dtype=float32)
Parameters:
  • alpha (int | float, optional) – The (improer) euler angle of rotation around the X-axis in radians.

  • beta (int | float, optional) – The (improer) euler angle of rotation around the Y-axis in radians.

  • gamma (int | float, optional) – The (improer) euler angle of rotation around the Z-axis in radians.

  • **kwargs – Keyword arguments are passed to the copy().

  • quat (list[int | float] | ndarray | None)

Returns:

A copy of the Thing set to the given orientation is returned.

Return type:

blue.MoveableThingType

scaled(scale, keep_pos=False, **kwargs)[source]#

This method creates a copy that is rescaled in size and position.

scaleint | float | None, optional

The scaling factor by which the Things size and position is increased.

keep_posbool

If set, the position is kept, otherwise, the position is scaled as well.

**kwargs

Keyword arguments are passed to the copy().

Returns:

A copy of the rescaled Thing.

Return type:

blue.MoveableThingType

Parameters:
  • scale (int | float)

  • keep_pos (bool)

property euler: ndarray#

Note that euler angles are not additive for rotations. Use rotate() for this.

Returns:

The orientation is represented as a vector containing the (improper) euler angles array([alpha, beta, gamma]).

Return type:

np.ndarray

property pos: ndarray#

Individual components of pos can be found in x, y and z.

Returns:

The position of the Thing is given in local coordinates.

Return type:

np.ndarray

property global_pos#

Individual components of global_pos can be found in global_x, global_y and global_z.

Returns:

The position of the Thing is given in global coordinates.

Return type:

np.ndarray

property alpha: float | None#

Note that euler angles are not additive for rotations. Use rotate() for this.

Returns:

The (improper) euler angle of rotation around the X-axis.

Return type:

float | None

property beta: float | None#

Note that euler angles are not additive for rotations. Use rotate() for this.

Returns:

The (improper) euler angle of rotation around the Y-axis.

Return type:

float | None

property gamma: float | None#

Note that euler angles are not additive for rotations. Use rotate() for this.

Returns:

The (improper) euler angle of rotation around the Z-axis.

Return type:

float | None

property quat#

Alternatively quaternions can be used for orientations. Where every euler angles are provided, a quat can be passed instead.

Return type:

np.ndarray

property x: float | None#

If the whole position should be updated use pos instead.

Returns:

The X-coordinate of the Things local position.

Return type:

float | None

property y: float | None#

If the whole position should be updated use pos instead.

Returns:

The Y-coordinate of the Things local position.

Return type:

float | None

property z: float | None#

If the whole position should be updated use pos instead.

Returns:

The Z-coordinate of the Things local position.

Return type:

float | None

property vel: ndarray#

The global velocity for all axis

Return type:

np.ndarray

property x_vel#

The global velocity of the X axis

Return type:

np.ndarray

property y_vel#

The global velocity of the Y axis

Return type:

np.ndarray

property z_vel#

The global velocity of the Z axis

Return type:

np.ndarray

property angular_vel: ndarray#

The global angular velocity for all axis

Return type:

np.ndarray