Download presentation
Presentation is loading. Please wait.
1
Affine Transformations
Jim Van Verth Lars M. Bishop
2
Affine Transformations
Extension of linear transforms Lines preserved Distances and angles can change Transform in an affine space Almost all apply to both vectors and points – exception is translation Essential Math for Games
3
Affine Transformations
The most common ones are translation, scale and rotation Translation moves an object along a direction vector Scale shrinks/grows the object size Rotation rotates the object around an axis vector Essential Math for Games
4
Affine Transformations
Can’t use 3x3 matrix for R3 R3 affine xforms Perform linear transforms, not affine transforms Need another representation Essential Math for Games
5
Essential Math for Games
What’s Wrong With A 3x3? Can’t construct a 3x3 matrix that will translate the point (0,0,0) The zeroes in the coordinate vector cancel out all the coefficients! Essential Math for Games
6
Homogeneous Coordinates
One way is to use homogeneous coordinates Initially developed in the 40s for use in geometry Later found their way into computer graphics Allow us to perform affine transforms via matrices Essential Math for Games
7
Homogeneous Coordinates
Convert point in Rn to one of equivalent points in homogeneous space RPn Point in RPn has n+1 coordinates So point in R3 (x y z) has corresponding points in RP3 (x’ y’ z’ w) Essential Math for Games
8
Homogeneous Coordinates
How to convert an R3 coordinate to its homogeneous representation Pick a number for the fourth element, w, and scale the real coordinate by it (x y z) => (xw yw zw w) Standard value for w is 1, so: (x y z) => (x y z 1) Essential Math for Games
9
Homogeneous Coordinates
Map back to R3 by dividing out the w (x' y' z' w) => (x'/w y'/w z'/w) Usually assume w = 1, so just drop the w (x' y' z' 1) => (x' y' z') But not always, so be careful! Essential Math for Games
10
Essential Math for Games
Homogeneous Matrices N-dimensional affine transformation is n+1 dimensional linear transformation A 3D homogeneous transformation matrix is a 4x4 matrix Treat 3D homogeneous point as a 4D vector Essential Math for Games
11
Translation Revisited
Remember translating the point (0,0,0)? No problem; right column is translation vector Essential Math for Games
12
Translation Txyz(a,b,c)
Essential Math for Games
13
Essential Math for Games
Transforming Point Can represent affine transform as block matrix multiplication Transform point P = (x, 1), get So y is translation part, what does A represent? Essential Math for Games
14
Essential Math for Games
Transforming Vectors Represent vector with w = 0 (x, y, z) => (x, y, z, 0) Can also write as v => (v, 0) Think of as point at infinity Essential Math for Games
15
Essential Math for Games
Transforming Vectors Apply affine transform to vector, get Applies linear transform A to vector So linear transforms are subset of affine transforms Note no translation: makes sense, vectors have no position! Essential Math for Games
16
Other Affine Transformations
Remaining affine transformations are also linear transformations Can be applied to vectors as well Notice that the top-left 3x3 block in the translation example was the identity? Just place the linear transform in the upper-left 3x3 block, as follows… Essential Math for Games
17
Essential Math for Games
Scaling Sxyz(a,b,c) Essential Math for Games
18
Rotating About the x-axis Rx()
Essential Math for Games
19
Rotating About the y-axis Ry()
Essential Math for Games
20
Rotation About the z-axis Rz()
Essential Math for Games
21
Essential Math for Games
Rotation Matrices Have some useful properties Are orthogonal, i.e., R-1 = RT Column vectors are transformed axis of old coordinate system We’ll see how we can use this later Essential Math for Games
22
Concatenation of Transformations
Transforms concatenated into a single matrix by multiplying them together, in the order they are to occur Can then use single matrix to perform transforms on many points Essential Math for Games
23
Essential Math for Games
Concatenation Can perform a series of transformations v’ = M1 v v’’ = M2 v’ w = M3 v’’ Substitute to get w = M3 M2 v’ w = M3 M2 M1 v Essential Math for Games
24
Essential Math for Games
Concatenation Can combine series into one matrix that performs all of them M = M3 M2 M1 w = M v Example: Euler rotations Essential Math for Games
25
Essential Math for Games
Euler Angles Common representation for 3D orientation (common best) Three Euler angles: Yaw = shaking your head, “no” Pitch = nodding your head, “yes” Roll = cocking your head sideways Essential Math for Games
26
Essential Math for Games
The Euler Transform Each angle corresponds to a rotation about an axis (dependent on coordinate system) z x y Essential Math for Games
27
Essential Math for Games
The Euler Transform Looking down the x-axis: Yaw = Rz Pitch = Ry Roll = Rx z x y Essential Math for Games
28
Essential Math for Games
The Euler Transform For this coordinate system, the Euler Transform E E(y,p,r) = Rx(r) Ry(p) Rz(y) Again, E is orthogonal (it’s a pure rotation matrix) Essential Math for Games
29
Concatentation of Transforms
Can concatenate any sequence of scale, rotation, translate Matrix products are non-commutative, so the order matters Translating the point (0, 0, 0) and then rotating will not yield the same point as rotating (0, 0, 0) then translating (rotation of (0, 0, 0) does nothing) Essential Math for Games
30
Concatentation of Transforms
Similarly, scaling and rotation are non-commutative Example: rotate (1 0 0) by 90° around z, scale by (sx, sy, sz), get (0 sy 0) scale (1 0 0) by (sx, sy, sz), rotate (1 0 0) by 90° around z, get (0 sx 0) Essential Math for Games
31
Essential Math for Games
Transformation Order To perform scale, then rotation, then translation (generally the order desired), use Essential Math for Games
32
Essential Math for Games
Matrix Breakdown Rotation, scale in upper left 3x3 Translation rightmost column Does rotation/scale first, then translate Essential Math for Games
33
Essential Math for Games
Better Format Problem: want to Translate object in space and change rotation and scale arbitrarily Handle rotation/scale separately Can’t do easily with 4x4 matrix format Involves SVD, Polar decomposition Messy, but we can do better using… Essential Math for Games
34
Essential Math for Games
Rigid Body Transforms Any sequence of translation and rotation transformations Not scale or shear Object shape is not affected (preserves angles and lengths) Usually include uniform scale despite this Essential Math for Games
35
Essential Math for Games
Better Format Scale – one uniform scale factor s Rotation – 3x3 matrix R Translation – single vector t Essential Math for Games
36
Essential Math for Games
Better Format Want to concatenate transforms T1, T2 in this form, or Do this by Essential Math for Games
37
Essential Math for Games
Better Format Advantages Clear what each part does Easier to change individual elements Concat: 39 mult 27 add vs. 48 mult 32 add Disadvantages Eventually have to convert to 4x4 matrix anyway for renderer/video card Essential Math for Games
38
Essential Math for Games
Better Format Matrix conversion Essential Math for Games
39
Inverting Rigid Body Xforms
We can easily invert our rigid body transforms symbolically: Essential Math for Games
40
Inverting Rigid Body Xforms (2)
In fact, the result itself may be written as a rigid body transform: Essential Math for Games
41
Essential Math for Games
References Rogers, F. David and J. Alan Adams, Mathematical Elements for Computer Graphics, 2nd Ed, McGraw-Hill, 1990. Watt, Alan, 3D Computer Graphics, Addison-Wesley, Wokingham, England, 1993. Essential Math for Games
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.