Rotation Matrices¶
Definition of rotation matrices¶
rotmat.R()
… 3D rotation matrix for rotation about a coordinate axis
Conversion Routines¶
rotmat.convert()
… Convert a rotation matrix to the corresponding quaternionrotmat.sequence()
… Calculation of Euler, Fick/aeronautic, Helmholtz anglesrotmat.seq2quat()
… Calculation of quaternions from Euler, Fick/aeronautic, Helmholtz angles
Symbolic matrices¶
rotmat.R_s()
… symbolix matrix for rotation about a coordinate axis
For example, you can e.g. generate a Fick-matrix, with
R_Fick = R_s(2, ‘theta’) * R_s(1, ‘phi’) * R_s(0, ‘psi’)
Details¶
Routines for working with rotation matrices
-
rotmat.
R
(axis=0, angle=90)[source]¶ Rotation matrix for rotation about a cardinal axis. The argument is entered in degree.
Parameters: - axis (skalar) – Axis of rotation, has to be 0, 1, or 2
- alpha (float) – rotation angle [deg]
Returns: R
Return type: rotation matrix, for rotation about the specified axis
Examples
>>> rotmat.R(axis=0, alpha=45) array([[ 1. , 0. , 0. ], [ 0. , 0.70710678, -0.70710678], [ 0. , 0.70710678, 0.70710678]])
>>> rotmat.R(axis=0) array([[ 1. , 0. , 0. ], [ 0. , 0. , -1. ], [ 0. , 1. , 0. ]])
>>> rotmat.R(1, 45) array([[ 0.70710678, 0. , 0.70710678], [ 0. , 1. , 0. ], [-0.70710678, 0. , 0.70710678]])
>>> rotmat.R(axis=2, alpha=45) array([[ 0.70710678, -0.70710678, 0. ], [ 0.70710678, 0.70710678, 0. ], [ 0. , 0. , 1. ]])
-
rotmat.
R_s
(axis=0, angle='alpha')[source]¶ Symbolic rotation matrix about the given axis, by an angle with the given name
Returns: R_symbolic Return type: symbolic matrix for rotation about the given axis Examples
>>> R_yaw = R_s(axis=2, angle='theta')
>>> R_nautical = R_s(2) * R_s(1) * R_s(0)
-
rotmat.
convert
(rMat, to='quat')[source]¶ Converts a rotation matrix to the corresponding quaternion. Assumes that R has the shape (3,3), or the matrix elements in columns
Parameters: - rMat (array, shape (3,3) or (N,9)) – single rotation matrix, or matrix with rotation-matrix elements.
- to (string) – Currently, only ‘quat’ is supported
Returns: outQuat – corresponding quaternion vector(s)
Return type: array, shape (4,) or (N,4)
Notes
\[\begin{split}\vec q = 0.5*copysign\left( {\begin{array}{*{20}{c}} {\sqrt {1 + {R_{xx}} - {R_{yy}} - {R_{zz}}} ,}\\ {\sqrt {1 - {R_{xx}} + {R_{yy}} - {R_{zz}}} ,}\\ {\sqrt {1 - {R_{xx}} - {R_{yy}} + {R_{zz}}} ,} \end{array}\begin{array}{*{20}{c}} {{R_{zy}} - {R_{yz}}}\\ {{R_{xz}} - {R_{zx}}}\\ {{R_{yx}} - {R_{xy}}} \end{array}} \right)\end{split}\]More info under http://en.wikipedia.org/wiki/Quaternion
Examples
>>> rotMat = array([[cos(alpha), -sin(alpha), 0], >>> [sin(alpha), cos(alpha), 0], >>> [0, 0, 1]]) >>> rotmat.convert(rotMat, 'quat') array([[ 0.99500417, 0. , 0. , 0.09983342]])
-
rotmat.
seq2quat
(rot_angles, seq='nautical')[source]¶ This function takes a angles from sequenctial rotations and calculates the corresponding quaternions.
Parameters: - rot_angles (ndarray, nx3) – sequential rotation angles [deg]
- seq (string) –
Has to be one the following:
- Euler … Rz * Rx * Rz
- Fick … Rz * Ry * Rx
- nautical … same as “Fick”
- Helmholtz … Ry * Rz * Rx
Returns: quats – corresponding quaternions
Return type: ndarray, nx4
Examples
>>> skin.rotmat.seq2quat([90, 23.074, -90], seq='Euler') array([[ 0.97979575, 0. , 0.2000007 , 0. ]])
Notes
The equations are longish, and can be found in 3D-Kinematics, 4.1.5 “Relation to Sequential Rotations”
-
rotmat.
sequence
(R, to='Euler')[source]¶ This function takes a rotation matrix, and calculates the corresponding angles for sequential rotations.
R_Euler = R3(gamma) * R1(beta) * R3(alpha)
Parameters: - R (ndarray, 3x3) – rotation matrix
- to (string) –
Has to be one the following:
- Euler … Rz * Rx * Rz
- Fick … Rz * Ry * Rx
- nautical … same as “Fick”
- Helmholtz … Ry * Rz * Rx
Returns: - gamma (third rotation (left-most matrix))
- beta (second rotation)
- alpha (first rotation(right-most matrix))
Notes
The following formulas are used:
Euler:
\[ \begin{align}\begin{aligned}\beta = -arcsin(\sqrt{ R_{xz}^2 + R_{yz}^2 }) * sign(R_{yz})\\\gamma = arcsin(\frac{R_{xz}}{sin\beta})\\\alpha = arcsin(\frac{R_{zx}}{sin\beta})\end{aligned}\end{align} \]nautical / Fick:
\[ \begin{align}\begin{aligned} \theta = arctan(\frac{R_{yx}}{R_{xx}})\\\phi = arcsin(R_{zx})\\ \psi = arctan(\frac{R_{zy}}{R_{zz}})\end{aligned}\end{align} \]Note that it is assumed that psi < pi !
Helmholtz:
\[ \begin{align}\begin{aligned}\theta = arcsin(R_{yx})\\\phi = -arcsin(\frac{R_{zx}}{cos\theta})\\\psi = -arcsin(\frac{R_{yz}}{cos\theta})\end{aligned}\end{align} \]Note that it is assumed that psi < pi