Accelerating the pace of engineering and science

# Documentation

## Representations of Body Orientation

You represent a SimMechanics™ body's orientation by specifying the orientation of its center of gravity coordinate system (CG CS) axes relative to some other set of axes, either the CS axes of an adjoining body or the World CS axes. No reorientation is represented by "no rotation" or the rotational identity.

A general rotation of a body in three dimensions has three independent degrees of freedom. There are many equivalent and interconvertible ways to represent these degrees of freedom . The Body and related Body Sensor and RotationMatrix2VR blocks use the following representations. The block reference pages for these blocks discuss block-specific details.

### Axis-Angle Representation

The axis-angle representation of a rotation is the most fundamental form. Specify a rotation axis n, then rotate by the right-hand rule about that axis by some angle θ. The vector n = (nx,ny,nz) is a three-component unit vector, where n·n = nx2 + ny2 + nz2 = 1. The axis n is sometimes called the eigenaxis.

SimMechanics models do not make direct use of the axis-angle representation, but it is the starting point for deriving other forms. It is also used extensively in mechanical applications such as computer-aided design and robotics.

The axis-angle representation is usually written as a 4-vector: [nx ny nz θ]. Of the four numbers, three are independent, because n always has unit length. The remaining freedom in this vector allows you to specify a direction (two angles) and the size and sense of the rotation about that directional axis (magnitude and sign of θ).

To describe continuous rotation in time, treat n and θ as functions of time.

### Quaternion Representation

A quaternion represents a three-dimensional rotation as a four-component row vector of unit length:

$q=\left[{n}_{x}\mathrm{sin}\left(\theta /2\right),{n}_{y}\mathrm{sin}\left(\theta /2\right),{n}_{z}\mathrm{sin}\left(\theta /2\right),\mathrm{cos}\left(\theta /2\right)\right]=\left[{q}_{\text{v}},{q}_{\text{s}}\right]$

with q*q = qv·qv + qs2 = 1. This definition uses the axis-angle representation defined above. The rotation angle about that axis is θ. To describe continuous rotation in time, treat n and θ as functions of time. Unlike some rotation representations, quaternions never become singular.

For more about quaternions, see Bell and Shuster in the chapter references.

### Rotation Matrix Representation

The axis-angle representation also defines the rotation matrix R in exponential form R = exp(θ J), where the Jk are real, antisymmetric matrices, and J = nxJ1 + ny J2 + nz J3. The rotation matrix R is orthogonal: RRT = RTR = I.

The J matrices are related to the antisymmetric permutation symbol ɛijk.

${\left({J}^{\text{j}}\right)}_{\text{ik}}={\epsilon }_{\text{ijk}}$

The exponential R is reduced to closed form by the Rodrigues identity:

where I is the identity matrix, and J is given by

$n\cdot J=\left(\begin{array}{ccc}0& -{n}_{z}& {n}_{y}\\ {n}_{z}& 0& -{n}_{x}\\ -{n}_{y}& {n}_{x}& 0\end{array}\right)$

The inverse of R is identical to its transpose RT. You can also obtain the inverse by replacing θ with θ or by reversing the direction of n.

To describe continuous rotation in time, treat n and θ as functions of time.

### Euler Angle Representation

An alternative representation for R is to rotate, in succession, about three independent axes, by three independent Euler angles. A full rotation R starting in World composes by multiplying the matrices successively on the left:

RBW = R3*R2*R1

A full rotation R starting in a body CS composes by multiplying the matrices successively on the right:

RWB = R1*R2*R3

The Euler angle convention is to

1. Rotate about one body coordinate axis (which rotates the other two).

2. Then rotate about a second body coordinate axis (rotated from its original direction) not identical to the first.

3. Lastly, rotate about another body coordinate axis not identical to the second.

Thus there are 3*2*2 = 12 possible Euler angle rotation sequences. The rotation axis sequences Z-X-Z and Z-Y-X are common. Rotation angles are often labeled as θ1, θ2, θ3 or Φ, θ, Ψ as the first, second, and third angles, respectively. For example,

RBW = RX1)*RY2)*RZ3)

RWB = RZ(Φ)*RX(θ)*RZ(Ψ)

A two-dimensional rotation about a fixed axis requires one angle. For example, rotating the x- and y-axes about the z-axis by Φ is represented by

${R}_{Z}\left(\varphi \right)=\left(\begin{array}{ccc}\mathrm{cos}\varphi & -\mathrm{sin}\varphi & 0\\ \mathrm{sin}\varphi & \mathrm{cos}\varphi & 0\\ 0& 0& 1\end{array}\right)$

To describe continuous rotation in time, treat the Euler angles as functions of time. The Euler angle representation is singular in certain limiting situations. Such singularities are artifacts of the Euler angle form and have no geometric or physical significance.

### Converting Rotation Representations

Certain SimMechanics blocks make use of different rotation representations.

• The Body block makes direct use of the Euler angle, rotation matrix, and quaternion representations.

• The Body Sensor block makes use of the rotation matrix.

• The RotationMatrix2VR block uses the rotation matrix and axis-angle forms.

The four rotation representations presented in this section are equivalent. You can represent a rotation equally well with any one of them. Some applications, however, tend to favor one representation over the others, and certain representations are singular in certain limits. It is helpful to know how to convert the various rotation representations into one another. The following summaries group the conversion formulas into one place.

#### Transforming the Axis-Angle Representation

The rotation axis unit vector n and the rotation angle θ define this representation, which is discussed in detail in Axis-Angle Representation preceding. This representation defines the quaternion and rotation matrix representations:

$n\cdot J=\left(\begin{array}{ccc}0& -{n}_{z}& {n}_{y}\\ {n}_{z}& 0& -{n}_{x}\\ -{n}_{y}& {n}_{x}& 0\end{array}\right)$

#### Transforming the Quaternion Representation

The quaternion is a vector-scalar pair, q = [qv qs], defined by Quaternion Representation preceding. You can recover the axis-angle representation from the quaternion components:

$\begin{array}{l}\theta =2\cdot {\mathrm{cos}}^{-1}\left({q}_{\text{s}}\right)\\ n={q}_{\text{v}}/\sqrt{1-{q}_{\text{s}}{}^{2}}\end{array}$

You can also construct the equivalent rotation matrix R from q.

The term ${q}_{\text{v}}^{\text{T}}\otimes {q}_{\text{v}}$ is the outer product of qv with itself, the 3-by-3 matrix of qv components multiplied by each other.

#### Transforming the Rotation Matrix Representation

The rotation matrix R is an orthogonal 3-by-3 matrix: RRT = RTR = I, defined in Rotation Matrix Representation preceding. You can invert the rotation matrix representation to obtain the equivalent representations for the quaternion q = [qv qs] and axis-angle (n, θ)

$\begin{array}{l}{q}_{\text{s}}=\frac{1}{2}\sqrt{Tr\left(R\right)+1}\\ {q}_{\text{v}}=Tr\left(J\ast R\right)/\left(2\sqrt{Tr\left(R\right)+1}\right)\\ \theta =2\cdot {\mathrm{cos}}^{-1}\left(\frac{1}{2}\sqrt{Tr\left(R\right)+1}\right)\\ n=Tr\left(J\ast R\right)/\left(\sqrt{Tr\left(R\right)+1}\cdot \sqrt{3-Tr\left(R\right)}\right)\end{array}$

The trace Tr of a matrix is the sum of its diagonal elements.

The J matrices constitute a 3-vector of matrices defined by the antisymmetric permutation symbol, (Jj)ik = ɛijk. See The Permutation Symbol and the Vector Cross Product preceding for more details.

The RotationMatrix2VR block converts the rotation matrix to the axis-angle representation.

#### Transforming the Euler Angle Representation

The Euler angle representation of a rotation, defined by Euler Angle Representation preceding, stands apart from the other three, insofar as you cannot derive it from the axis-angle representation. It depends on the choice of rotation axis sequence, which generates multiple definition conventions. The Euler angle representation, at certain limits, can also be singular. Use caution with Euler angle expressions.

If you choose a convention and three angles, then compute R, you can convert R to the other representations by the use of Transforming the Rotation Matrix Representation above. But given the nine components of R, you must find the Euler angles by inverting the nine equations that result from this matrix equation. (Only three equations of the nine are independent.) In some cases, angles can be read from R by inspection.

For example, choose rotations with respect to a Body coordinate system (CS) triad, in a commonly used rotation axis sequence Z-X-Z, with Φ, θ, Ψ as the respective angles. The rotation matrix is RWB = R1(Φ)*R2(θ)*R3(Ψ),

$\begin{array}{l}{R}_{\text{WB}}\left(\varphi ,\theta ,\psi \right)=\left(\begin{array}{ccc}\mathrm{cos}\varphi & -\mathrm{sin}\varphi & 0\\ \mathrm{sin}\varphi & \mathrm{cos}\varphi & 0\\ 0& 0& 1\end{array}\right)\left(\begin{array}{ccc}1& 0& 0\\ 0& \mathrm{cos}\theta & -\mathrm{sin}\theta \\ 0& \mathrm{sin}\theta & \mathrm{cos}\theta \end{array}\right)\left(\begin{array}{ccc}\mathrm{cos}\psi & -\mathrm{sin}\psi & 0\\ \mathrm{sin}\psi & \mathrm{cos}\psi & 0\\ 0& 0& 1\end{array}\right)\\ =\left(\begin{array}{ccc}\mathrm{cos}\varphi \mathrm{cos}\psi -\mathrm{sin}\varphi \mathrm{cos}\theta \mathrm{sin}\psi & -\mathrm{cos}\varphi \mathrm{sin}\psi -\mathrm{sin}\varphi \mathrm{cos}\theta \mathrm{cos}\psi & \mathrm{sin}\varphi \mathrm{sin}\theta \\ \mathrm{sin}\varphi \mathrm{cos}\psi +\mathrm{cos}\varphi \mathrm{cos}\theta \mathrm{sin}\psi & -\mathrm{sin}\varphi \mathrm{sin}\psi +\mathrm{cos}\varphi \mathrm{cos}\theta \mathrm{cos}\psi & -\mathrm{cos}\varphi \mathrm{sin}\theta \\ \mathrm{sin}\theta \mathrm{sin}\psi & \mathrm{sin}\theta \mathrm{cos}\psi & \mathrm{cos}\theta \end{array}\right)\end{array}$

In this convention, you can read θ from the R33 component, then find Ψ from the R32 or R31 component. Obtain Φ from one of the other components, using cos2Φ + sin2Φ = 1, or by multiplying from the right by R3ΨT, then R2θT. The second method yields a unique solution for the sine and cosine of Φ.

### Converting the Angular Velocity

The rotation matrix R is defined in Representations of Body Motion and Rotation Matrix Representation preceding.

The angular velocity vector ω is the rate at which a spinning CS rotates. R and the antisymmetric matrix Ω define ω:

$\begin{array}{l}\Omega =+\left(\text{d}R/\text{dt}\right)\cdot {R}^{\text{T}}=-R\cdot \left(\text{d}{R}^{\text{T}}/\text{dt}\right)\\ {\Omega }_{\text{ik}}=\text{+}{\sum }_{\text{j}}{\epsilon }_{\text{ijk}}{\omega }_{\text{j}}\\ {\omega }_{\text{j}}=\left(\frac{\text{1}}{\text{2}}\right){\sum }_{\text{ik}}{\epsilon }_{\text{ijk}}{\Omega }_{\text{ik}}\end{array}$

You can also express the angular velocity in terms of Euler angles, by choosing a particular set of angles to represent R. See Euler Angle Representation and Transforming the Euler Angle Representation preceding.

The quaternion derivative is also related to the angular velocity:

$\begin{array}{l}\text{d}{q}_{\text{v}}\text{/dt}=\left(\frac{\text{1}}{\text{2}}\right)\left({q}_{\text{s}}{\omega }_{\text{Body}}-{q}_{\text{v}}\text{x}{\omega }_{\text{Body}}\right)\\ \text{d}{q}_{\text{s}}\text{/dt}=-\left(\frac{\text{1}}{\text{2}}\right)\text{(}{q}_{\text{v}}\cdot {\omega }_{\text{Body}}\text{)}\end{array}$