MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB技术文章 (https://www.labfans.com/bbs/forumdisplay.php?f=25)
-   -   Matrices In Action, Grafix 2.0 - Cleve Moler on Mathematics and Computing (https://www.labfans.com/bbs/showthread.php?t=27375)

poster 2023-02-05 01:01

Matrices In Action, Grafix 2.0 - Cleve Moler on Mathematics and Computing
 
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.

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

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 [URL="https://blogs.mathworks.com/cleve/files/Grafix_mzip.m"]is availble here.[/URL]

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.

[IMG]http://blogs.mathworks.com/cleve/files/grafix.png[/IMG]

[B]Rotations[/B]

The [I]homogeneous coordinates[/I] 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] $$

[B]Pitch, Roll, and Yaw[/B]

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

[IMG]http://blogs.mathworks.com/cleve/files/pitchgif.gif[/IMG]

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

[IMG]http://blogs.mathworks.com/cleve/files/rollgif.gif[/IMG]

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

[IMG]http://blogs.mathworks.com/cleve/files/yawgif.gif[/IMG]

[B]Translations[/B]

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.

[B]Horizontal and Vertical[/B]

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

$T_x$, left and right.

[IMG]http://blogs.mathworks.com/cleve/files/Txgif.gif[/IMG]

$T_y$, back and forth.

[IMG]http://blogs.mathworks.com/cleve/files/Tygif.gif[/IMG]

$T_z$, up and down.

[IMG]http://blogs.mathworks.com/cleve/files/Tzgif.gif[/IMG]

[B]Scalings[/B]

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] $$

[B]Larger and Smaller[/B]

$S$

[IMG]http://blogs.mathworks.com/cleve/files/Sgif.gif[/IMG]

[B]Suggestions[/B]

Refresh your browser to syncronize the animations.

Download your own self-archiving copies of
[LIST][*][URL="https://blogs.mathworks.com/cleve/files/Grafix_mzip.m"]Grafix[/URL][*][URL="https://blogs.mathworks.com/cleve/files/Qube_mzip-1.m"]Qube[/URL][/LIST][RIGHT][COLOR=gray][I]
[URL="javascript:grabCode_b13c7ab1c73c4ad7909fa2d7cd9764f2()"][I]Get the MATLAB code (requires JavaScript)[/I][/URL]

Published with MATLAB® R2023a
[/I][/COLOR][/RIGHT]




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


所有时间均为北京时间。现在的时间是 01:11

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.