Graphics Programs Reference
In-Depth Information
5. Rotate the result of step 4 by
A
−
1
(which equals
A
T
).
When these five steps are performed on a point (
x, y, z
), the effect is to rotate
the point through an angle
θ
about
u
. In practice, the five steps are combined by
multiplying the five matrices above, as shown in the listing of Figure 1.27. The result
is identical to Equation (1.32).
tm=Sqrt[x^2+y^2];
a={{x/tm,-y/tm,0},{y/tm,x/tm,0},{0,0,1}};
b={{z,0,Sqrt[1-z^2]},{0,1,0},{-Sqrt[1-z^2],0,z}};
c={{Cos[t],-Sin[t],0},{Sin[t],Cos[t],0},{0,0,1}};
FullSimplify[a.b.c.Transpose[b].Transpose[a] /. x^2+y^2->1-z^2]
Figure 1.27:
Mathematica
Code for a General Rotation.
1.4.4 Givens Rotations
The general rotation matrix, Equation (1.32), can be constructed for any general ro-
tation in three dimensions. Given such a matrix
A
, it is possible to reduce it to a
product of rotation matrices that cause the same rotation by performing a sequence of
rotations about the coordinate axes. This process [Givens 58] is based on the QR
decomposition of matrices, a subject discussed in any text on matrices, and it re-
sults in a set of
Givens rotations
. Each Givens rotation matrix
T
i,j
is identified by
two indexes,
i
and
j
,where
i>j
. The matrix is an identity matrix except for the
two diagonal elements (
i, i
)and(
j, j
) that are cosines of some angle and for the two
off-diagonal elements (
i, j
)and(
j, i
)thatarethe
±
sin of the same angle.
Specifi-
cally,
T
i,j
[
i, i
]=
T
i,j
[
j, j
]=
c
and
T
i,j
[
j, i
]=
−
T
i,j
[
i, j
]=
s
,where
c
=
A
[
j, j
]
/D
,
s
=
A
[
i, j
]
/D
,and
D
=
A
[
j, j
]
2
+
A
[
i, j
]
2
. The special construction of
T
i,j
implies
that the matrix product
T
i,j
A
transforms
A
toamatrixwhose(
i, j
)th element is zero.
Once a general rotation matrix
A
is given, its Givens rotations can be found by
preparing the Givens rotation matrices
T
i,j
that zero those elements of
A
located below
the main diagonal, column by column, from the bottom up. Figure 1.28 is a listing of
Matlab
code that does that for the rotation matrix that rotates point (1
,
1
,
1) to the
x
axis.
The three rotation matrices produced by this computation are listed in Figure 1.29,
where they are used to rotate point (1
,
1
,
1) to the
x
axis. Matrix
T1
rotates (1
,
1
,
1)
45
◦
about the
y
axis to (1
.
4142
,
1
,
0), which is rotated by
T2
35
.
26
◦
about the
z
axis to
(1
.
7321
,
0
,
0), which is trivially rotated by
T3
15
◦
about the
x
axis to itself.
1.4.5 Quaternions
Appendix B is a general introduction to quaternions and should be reviewed before
reading ahead. Quaternions can elegantly express arbitrary rotations in three dimen-
sions. Those familiar with complex numbers may have noticed that a rotation in two
Search WWH ::
Custom Search