Presentation is loading. Please wait.

Presentation is loading. Please wait.

Affine Transformations Jim Van Verth Lars M. Bishop

Similar presentations


Presentation on theme: "Affine Transformations Jim Van Verth Lars M. Bishop"— Presentation transcript:

1 Affine Transformations Jim Van Verth Lars M. Bishop

2 Essential Math for Games 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

3 Essential Math for Games 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

4 Essential Math for Games Affine Transformations Can’t use 3x3 matrix for R 3  R 3 affine xforms Perform linear transforms, not affine transforms Need another representation

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!

6 Essential Math for Games 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

7 Essential Math for Games Homogeneous Coordinates Convert point in R n to one of equivalent points in homogeneous space RP n Point in RP n has n+1 coordinates So point in R 3 ( x y z ) has corresponding points in RP 3 ( x’ y’ z’ w )

8 Essential Math for Games Homogeneous Coordinates How to convert an R 3 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 )

9 Essential Math for Games Homogeneous Coordinates Map back to R 3 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!

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

11 Essential Math for Games Translation Revisited Remember translating the point (0,0,0) ? No problem; right column is translation vector

12 Essential Math for Games Translation T xyz (a,b,c)

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?

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

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!

16 Essential Math for Games 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…

17 Essential Math for Games Scaling S xyz (a,b,c)

18 Essential Math for Games Rotating About the x-axis R x (  )

19 Essential Math for Games Rotating About the y-axis R y (  )

20 Essential Math for Games Rotation About the z-axis R z (  )

21 Essential Math for Games Rotation Matrices Have some useful properties  Are orthogonal, i.e., R -1 = R T  Column vectors are transformed axis of old coordinate system  We’ll see how we can use this later

22 Essential Math for Games 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

23 Essential Math for Games Concatenation Can perform a series of transformations  v’ = M 1  v  v’’ = M 2  v’  w = M 3  v’’ Substitute to get  w = M 3  M 2  v’  w = M 3  M 2  M 1  v

24 Essential Math for Games Concatenation Can combine series into one matrix that performs all of them  M = M 3  M 2  M 1  w = M  v Example: Euler rotations

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

26 Essential Math for Games The Euler Transform Each angle corresponds to a rotation about an axis (dependent on coordinate system)

27 Essential Math for Games The Euler Transform Looking down the x-axis: Yaw = R z Pitch = R y Roll = R x

28 Essential Math for Games The Euler Transform For this coordinate system, the Euler Transform E E(y,p,r) = R x (r) R y (p) R z (y) Again, E is orthogonal (it’s a pure rotation matrix)

29 Essential Math for Games 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)

30 Essential Math for Games Concatentation of Transforms Similarly, scaling and rotation are non- commutative Example:  rotate (1 0 0) by 90° around z, scale by ( s x, s y, s z ), get (0 s y 0)  scale (1 0 0) by (s x, s y, s z ), rotate (1 0 0) by 90° around z, get (0 s x 0)

31 Essential Math for Games Transformation Order To perform scale, then rotation, then translation (generally the order desired), use

32 Essential Math for Games Matrix Breakdown Rotation, scale in upper left 3x3 Translation rightmost column Does rotation/scale first, then translate

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…

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

35 Essential Math for Games Better Format Scale – one uniform scale factor s Rotation – 3x3 matrix R Translation – single vector t

36 Essential Math for Games Better Format Want to concatenate transforms T 1, T 2 in this form, or Do this by

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

38 Essential Math for Games Better Format Matrix conversion

39 Essential Math for Games Inverting Rigid Body Xforms We can easily invert our rigid body transforms symbolically:

40 Essential Math for Games Inverting Rigid Body Xforms (2) In fact, the result itself may be written as a rigid body transform:

41 Essential Math for Games References Rogers, F. David and J. Alan Adams, Mathematical Elements for Computer Graphics, 2 nd Ed, McGraw-Hill, Watt, Alan, 3D Computer Graphics, Addison- Wesley, Wokingham, England, 1993.


Download ppt "Affine Transformations Jim Van Verth Lars M. Bishop"

Similar presentations


Ads by Google