PDA

查看完整版本 : Matrices In Action, Grafix 2.0 - Cleve Moler on Mathematics and Computing


poster
2023-02-05, 01:01
The 4-by-4 matrices in the panels on the following screenshots are at the heart of computer graphics. They describe objects moving in three-dimensional space and are essential to MATLAB's Handle Graphics, to CAD (Computer Added Design) packages, to CGI (Computer Graphics Imagery) in films, and to most popular video games.

Contents


Grafix 2.0 (https://www.labfans.com/bbs/#4c54a017-4a2d-4bd0-b5de-085c77696298)
Rotations (https://www.labfans.com/bbs/#19ccc0f8-ccd0-45a3-a624-c4f466eea2af)
Pitch, Roll, and Yaw (https://www.labfans.com/bbs/#4028a6e9-0449-4846-8e6e-c9a2c5ad64b6)
Translations (https://www.labfans.com/bbs/#e6dc8b74-fe6e-4fb5-a343-2b8fbfe28558)
Horizontal and Vertical (https://www.labfans.com/bbs/#9dbcd88d-756a-475c-bd7e-237261a3cdbe)
Scalings (https://www.labfans.com/bbs/#54cb3b88-904f-441b-9c61-91dca0a68c0d)
Larger and Smaller (https://www.labfans.com/bbs/#9bfb2311-6f44-4f2b-85aa-f09554da0cc6)
Suggestions (https://www.labfans.com/bbs/#ef53d281-53a4-437e-80f0-93b331367abf)

Grafix 2.0

Here is the opening screen from version 2.0 of Grafix, my tool for investigating the matrices involved in 3-D computer graphics. The MATLAB code for Grafix is availble here. (https://blogs.mathworks.com/cleve/files/Grafix_mzip.m)

I am interested in the matrix in the panel, which I call M. Many matrices like this one describe the dyamic transformations to be made on a set of target objects in a complex three-dimensional scene. This particular M is the product of a scaling and a rotation that results in the size and orientation of the plane shown.

I also want to point out the coordinate axes being used. This is view(3), MATLAB's default 3-D cordinate system. The positive $x$-axis goes up and to the right on the screen, the positive $y$-axis up and to the left, and the positive $z$-axis goes straight up.

http://blogs.mathworks.com/cleve/files/grafix.png

Rotations

The homogeneous coordinates system used in modern computer graphics makes it possible to describe rotations, translations and many other operations with 4-by-4 matrices. These matrices operate on vectors with the position of an object in the first three components and, for now, a one as the fourth component, eg. [ $x$, $y$, $z$, 1 ]',

Rotations are described by products of these matrices, each of which operates on only two of the first three components of the vector. The first matrix, $R_x$, leaves $x$ unchanged while it rotates $y$ and $z$. The second matrix, $R_y$, leaves $y$ unchanged while it rotates $x$ and $z$. And the third matrix, $R_z$, leaves $z$ unchanged while it rotates $x$ and $y$.

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

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

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

Pitch, Roll, and Yaw

The terms pitch, roll and yaw are often used to describe the motion of vehicles like aircraft, marine craft, and spacecraft. Pitch is $R_x$, rotation about the $x$-axis.

http://blogs.mathworks.com/cleve/files/pitchgif.gif

Roll is $R_y$, rotation about the $y$-axis.

http://blogs.mathworks.com/cleve/files/rollgif.gif

And yaw is $R_z$, rotation about the $z$-axis.

http://blogs.mathworks.com/cleve/files/yawgif.gif

Translations

Translations are described by matrices with values in the fourth column. Multiplying a vector by one of these matrices produces a translation in the direction of the corresponding axis.

$$ T_x(\delta) = \left[ \begin{array}{rrrr} 1 & 0 & 0 & \delta \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{array} \right] $$

$$ T_y(\delta) = \left[ \begin{array}{rrrr} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & \delta \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{array} \right] $$

$$ T_z(\delta) = \left[ \begin{array}{rrrr} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & \delta \\ 0 & 0 & 0 & 1 \end{array} \right] $$

While it is true that translations could be accomplished simply by adding the increment to the specified coordiate, the use of matrix multiplication allows translations to be combined in a uniform way with rotations and other operations. The arithmetic units on today's Graphics Processing Units, GPUs, are designed to do 4-by-4 matrix multiplications at speeds hundreds of times faster than general purpose Central Processing Units, CPUs.

Horizontal and Vertical

Inspired by David Singmaster's notation for Rubik's cubes, L, R, B, F, U, and D, we can use the descriptive terms left and right for horizontal motion in the $x$ direction; back and forth for horizontal motion in the $y$ direction; and up and down for vertical motion in the $z$ direction.

$T_x$, left and right.

http://blogs.mathworks.com/cleve/files/Txgif.gif

$T_y$, back and forth.

http://blogs.mathworks.com/cleve/files/Tygif.gif

$T_z$, up and down.

http://blogs.mathworks.com/cleve/files/Tzgif.gif

Scalings

This matrix applies a single scaling factor to all three axes.

$$ S(\sigma) = \left[ \begin{array}{rrrr} \sigma & 0 & 0 & 0 \\ 0 & \sigma & 0 & 0 \\ 0 & 0 & \sigma & 0 \\ 0 & 0 & 0 & 1 \end{array} \right] $$

Larger and Smaller

$S$

http://blogs.mathworks.com/cleve/files/Sgif.gif

Suggestions

Refresh your browser to syncronize the animations.

Download your own self-archiving copies of


Grafix (https://blogs.mathworks.com/cleve/files/Grafix_mzip.m)
Qube (https://blogs.mathworks.com/cleve/files/Qube_mzip-1.m)


Get the MATLAB code (requires JavaScript) (javascript:grabCode_b13c7ab1c73c4ad7909fa2d7cd9764f2())

Published with MATLAB® R2023a





More... (https://blogs.mathworks.com/cleve/2023/02/04/matrices-in-action-grafix-2-0/?s_tid=feedtopost)