Rotation Matrices

The matrices in the following animations are at the heart of computer graphics. They describe objects moving in three-dimensional space and are essential to MATLAB's Handle Graphics, to Computer Added Design packages, to Computer Graphics Imagery in films, and to most popular video games. Many modern computers contain GPUs,Graphic Processing Units, which are optimized to compute the product of these matrices.

Contents

Rotations

Thehomogeneous coordinatessystem used in today's computer graphics software and hardware makes it possible to describe rotations, translations and many other operations with 3-by-3 and 4-by-4 matrices. These matrices operate on vectors with the position of an object,x,yandz, in the first three components.

Rotations about the coordinate axes are described by three matrices. Rotations about thex-axis are produced by $R_x$, which rotatesyandz, while leavingxunchanged.

$$ R_x(\theta) = \left( \begin{array}{rrr} 1 & 0 & 0 \\ 0 & \cos{\theta} & -\sin{\theta} \\ 0 & \sin{\theta} & \cos{\theta} \end{array} \right) $$

Rotations about they-axis are generated by

$$ R_y(\theta) = \left( \begin{array}{rrr} \cos{\theta} & 0 & -\sin{\theta} \\ 0 & 1 & 0 \\ \sin{\theta} & 0 & \cos{\theta} \end{array} \right) $$

And, rotations aboutzare provided by

$$ R_z(\theta) = \left( \begin{array}{rrr} \cos{\theta} & -\sin{\theta} & 0 \\ \sin{\theta} & \cos{\theta} & 0 \\ 0 & 0 & 1 \\ \end{array} \right) $$

theta

Rotation angles are specified in degrees. Our MATLAB programs use the degree-based trig functionscosdandsind. Here are graphs of $\cos\theta$ and $-\sin\theta$ , evaluated with the angle $\theta$ going from0to360degrees in10-degree steps.

Compass

这是另一个看相同的数据,cosd(theta)and-sind(theta)fortheta = 0:10:360. The columns of the rotation matrix are the coordinates of the rotating dots. The blue dot starts at (0,1) and the orange dot starts at (1,0).

If you drop the zeros from the values oftheta, you are left with the integers from 1 to 36. This is the numbering in the international standard describing the compass direction of runways at airports. The initial position of our blue dot corresponds to runway 36 and the orange dot starts as runway 9.

Roll, Pitch, Yaw

Note: Refresh your browser to synchronize these animations.

For aircraft and space vehicles, rotation around thex-axis from nose to tail is known asroll.

Rotation about they-axis parallel to the wings ispitch.

And, rotation about the verticalz-axis isyaw.

Propeller

Our model of the Piper PA-24 Comanche has 97patches. One of them is the propeller. This animation of a rotating propeller is very similar to our earlier animation of the compass.

Cubelet

Qube, our digital Rubik's Cube simulator, uses 27 copies of a singlecubelet. This animation of a rotating cubelet shows a quarter turn clockwise aboutx, followed by a quarter turn clockwise aboutyand then a quarter turn counterclockwise aboutz. If these three rotations are repeated four times, the cubelet returns to its initial orientation. In the process, we see the traditional Rubik's colors of all six faces -- white, green and orange opposite yellow, blue and red.

Scramble

Note: Refresh your browser to synchronize these animations.

Rubick's Cube is all about rotations. Rotating the cubelets in any face of the puzzle, while leaving the rest of the puzzle fixed, is called a "move". Like any cube, Rubik's cube has six faces. Each move rotates one of the six faces in either a clockwise or counterclockwise direction. So, afternmoves, the puzzle is in one of12^npossible states. The challenge is to return the cube to its original orientation.

Here are six random rotations produced byscramble(6). Because12^6is2,985,984, this is just one of almost three million six-move scrambles.

Unscramble

One possible way to restore any starting condition is to retrace the moves that produced it. This is the "follow the breadcrumbs" algorithm. So, I call thisunscramble, rather thansolve.

Exercises

  • 1: Which rotation matrices and what values ofthetaare used in the animations?
  • 2 (not easy): When isunscamblea solution with the minimum number of moves?

Software

The source code forQubeis available from this link:Qube_May18_osf.m. Theosf,one single file, format is a self-extracting archive that expands into a directory of individual functions.




Published with MATLAB® R2022a

|

Comments

To leave a comment, please clickhereto sign in to your MathWorks Account or create a new one.