py3dframe.Frame.from_rotation_vector#
- classmethod Frame.from_rotation_vector(translation=None, rotation_vector=None, *, parent=None, setup_only=False, convention=0, degrees=False)[source]#
Create a Frame object from a rotation vector and translation.
A rotation vector is a 3D vector that represents a rotation in 3D space. The direction of the vector indicates the axis of rotation, and the magnitude (length) of the vector indicates the angle of rotation in radians.
See also
from_rotation()method to create a Frame from a Rotation object instead of a rotation vector.from_rotation_matrix()method to create a Frame from a rotation matrix instead of a rotation vector.from_quaternion()method to create a Frame from a quaternion instead of a rotation vector.from_euler_angles()method to create a Frame from euler angles instead of a rotation vector.from_axes()method to create a Frame from its axes (origin and basis vectors) instead of a rotation vector 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_vector (numpy.ndarray, optional) – The rotation vector of the transformation. It must be a 3 elements vector in radians. 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 rotation vector is in degrees. If False, the rotation vector is in radians. Default is False.
- Returns:
The Frame object created from the given rotation vector and translation.
- Return type:
Examples
Lets create a frame from a rotation vector 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 rotation vector \(\mathbf{r} = [0, 0, \pi/4]\).
import numpy from py3dframe import Frame rotation_vector = 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_rotation_vector(translation=t, rotation_vector=rotation_vector, 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
conventionparameter. The translation and the rotation vector 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.