py3dframe.Frame.from_euler_angles#

classmethod Frame.from_euler_angles(translation=None, euler_angles=None, *, parent=None, setup_only=False, convention=0, degrees=False, seq='xyz')[source]#

Create a Frame object from euler angles and translation.

The euler angles allows to represent any rotation by a sequence of three elemental rotations around the axes of a coordinate system. The sequence of the rotations must be specified with the seq parameter.

See also

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

  • from_rotation_matrix() method to create a Frame from a rotation matrix instead of euler angles.

  • from_quaternion() method to create a Frame from a quaternion instead of euler angles.

  • from_rotation_vector() method to create a Frame from a rotation vector instead of euler angles.

  • from_axes() method to create a Frame from its axes (origin and basis vectors) instead of euler angles 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.

  • euler_angles (numpy.ndarray, optional) – The euler angles of the transformation. It must be a 3 elements vector [alpha, beta, gamma] in radians with xyz convention. Default is None - the zero vector.

  • 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.

  • degrees (bool, optional) – If True, the euler angles are in degrees. If False, the euler angles are in radians. Default is False.

  • seq (str, optional) – The sequence of the euler angles. It must be a string of 3 characters chosen between ‘x’, ‘y’, and ‘z’. Default is “xyz”.

Returns:

The Frame object created from the given euler angles and translation.

Return type:

Frame

Examples

Lets create a frame from euler angles 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. The rotation matrix corresponding to the basis vectors in the convention 0 can be described with euler angles \([\alpha, \beta, \gamma] = [0, 0, \pi/4]\) in the ‘xyz’ sequence.

import numpy
from py3dframe import Frame

euler_angles = numpy.array([0, 0, numpy.pi/4]) # in radians
origin = numpy.array([-1, -2, -3])
t = origin

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

frame = Frame.from_euler_angles(translation=t, euler_angles=euler_angles, 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 euler angles 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.