Graphics Reference
In-Depth Information
y
z
Pitching
Yawing
x
Rolling
Figure 11.1: An airplane that flies along the x-axis can change direction by turning to the
left or right (yawing), pointing up or down (pitching), or simply spinning about its axis
(rolling).
Writing this out in matrices, we have
1
0
0
cos
θ
θ
01 0
0 sin
cos
φ −
sin
φ
0
M =
0 cos
ψ −
sin
ψ
sin
φ
cos
φ
0
0 sin
ψ
cos
ψ
sin
θ
0 cos
θ
0
0
1
(11.13)
.
cos
θ
cos
φ −
cos
θ
sin
φ
sin
θ
=
∗ −
sin
ψ
cos
θ
(11.14)
cos
ψ
cos
θ
, such products represent all possible
rotations. To see this, we'll show how to find
With the proper choice of
φ
,
θ
, and
ψ
φ
,
θ
, and
ψ
from a rotation matrix
M . In other words, having shown how to convert a (
φ
,
θ
,
ψ
) triple to a matrix, we'll
φ ,
θ ,
ψ ) , a triple with the property
show how to convert a matrix M to a triple (
that if we convert it to a matrix, we'll get M .
The ( 1, 3 ) entry of M , according to Equation 11.14, must be sin
is
just the arcsine of this entry; the number thus computed will have a non-negative
cosine. When cos
θ
,so
θ
θ
= 0, the ( 1, 1 ) and ( 1, 2 ) entries of M are positive multiples of
cos
φ
and
sin
φ
by the same multiplier; that means
φ
= atan2 (
m 21 , m 11 ) .We
can similarly compute
ψ
from the last entries in the second and third rows. In the
case where cos
are not unique (much as the longitude
of the North Pole is not unique). But if we pick
θ
= 0, the angles
φ
and
ψ
φ
= 0, we can use the lower-
left corner and atan2 to compute a value for
ψ
. The code is given in Listing 11.1,
where we are assuming the existence of a 3
3matrixclass, Mat33 , which uses
zero-based indexing. The angles returned are in radians, not degrees.
×
Listing 11.1: Code to convert a rotation matrix to a set of Euler angles.
1
2
3
4
5
6
7
8
void EulerFromRot(Mat33 m, out double psi,
out double theta,
out double phi)
{
theta = Math.asin(m[0,2]) //using C# 0-based indexing!
double costheta = Math.cos(th);
if (Math.abs(costheta) == 0){
phi=0;
 
Search WWH ::




Custom Search