py3dframe.Frame.from_rotation#

classmethod Frame.from_rotation(translation=None, rotation=None, *, parent=None, setup_only=False, convention=0)[source]#

Create a Frame object from a rotation (Rotation) and a translation.

See also

  • Rotation class to create and manipulate rotations.

  • from_rotation_matrix() method to create a Frame from a rotation matrix instead of a scipy Rotation object.

  • from_quaternion() method to create a Frame from a quaternion instead of a scipy Rotation object.

  • from_euler_angles() method to create a Frame from euler angles instead of a scipy Rotation object.

  • from_rotation_vector() method to create a Frame from a rotation vector instead of a scipy Rotation object.

  • from_axes() method to create a Frame from its axes (origin and basis vectors) instead of a rotation and a translation.

Parameters:
  • translation (numpy.ndarray, optional) – The translation vector of the transformation. It must be a 3 elements vector with shape (3, 1). Default is None - the zero vector.

  • rotation (Rotation, optional) – The rotation of the transformation. It must be a Rotation. Default is None - the identity rotation.

  • parent (Optional[Frame], optional) – The parent frame of the frame. Default is None - the global frame.

  • setup_only (bool, optional) – If True, the parent frame will be used only to define the frame and not to link the frames. Default is False.

  • convention (int, optional) – Integer in [0, 7] selecting the convention to express the transformation. Default is 0.

Returns:

The Frame object created from the given rotation and translation.

Return type:

Frame

Examples

Lets create a frame from a rotation and a translation.

We want to create the frame defined by the following origin and basis vectors in the parent frame coordinates:

  • Origin: \(O_F = [-1, -2, -3]\)

  • X-axis: \(\mathbf{e}_1 = [1, 1, 0] / \sqrt{2}\)

  • Y-axis: \(\mathbf{e}_2 = [-1, 1, 0] / \sqrt{2}\)

  • Z-axis: \(\mathbf{e}_3 = [0, 0, 1]\)

With convention 0, the frame is defined by the following formula:

\[\mathbf{X}_E = \mathbf{R} \mathbf{X}_F + \mathbf{T}\]

For \(\mathbf{X}_F = 0\) we have \(\mathbf{X}_E = O_F = \mathbf{T}\) so the translation vector is directly the origin of the frame in the parent frame coordinates. For \(\mathbf{X}_F = [1, 0, 0]\) we have \(\mathbf{X}_E = \mathbf{e}_1\) so the first column of the rotation matrix is the x-axis of the frame in the parent frame coordinates. For \(\mathbf{X}_F = [0, 1, 0]\) we have \(\mathbf{X}_E = \mathbf{e}_2\) so the second column of the rotation matrix is the y-axis of the frame in the parent frame coordinates. For \(\mathbf{X}_F = [0, 0, 1]\) we have \(\mathbf{X}_E = \mathbf{e}_3\) so the third column of the rotation matrix is the z-axis of the frame in the parent frame coordinates.

The frame can be created as follows:

import numpy
from py3dframe import Frame, Rotation

origin = numpy.array([-1, -2, -3])
x_axis = numpy.array([1, 1, 0]) / numpy.sqrt(2)
y_axis = numpy.array([-1, 1, 0]) / numpy.sqrt(2)
z_axis = numpy.array([0, 0, 1])

axes = numpy.column_stack((x_axis, y_axis, z_axis))
R = Rotation.from_matrix(axes)
t = origin

parent = ... # Define the parent frame if needed, otherwise parent=None to use the canonical frame.

frame = Frame.from_rotation(translation=t, rotation=R, convention=0, parent=parent)

print("Origin of the frame:", frame.origin)
print("X-axis of the frame:", frame.x_axis)
print("Y-axis of the frame:", frame.y_axis)
print("Z-axis of the frame:", frame.z_axis)
# Output:
# Origin of the frame: [[-1.] [-2.] [-3.]]
# X-axis of the frame: [[ 0.70710678] [ 0.70710678] [ 0.        ]]
# Y-axis of the frame: [[-0.70710678] [ 0.70710678] [ 0.        ]]
# Z-axis of the frame: [[0.] [0.] [1.]]

If you like to work with a given convention you can specify it with the convention parameter. The translation and the rotation must be given in this convention to create the frame.

You can also create the frame with convention 0 and then change the convention of the frame with the :attr`convention` attribute according to your preferences.