35

Affine Transformations Jim Van Verth NVIDIA Corporation ([email protected])[email protected]

Embed Size (px)

Citation preview

Page 1: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com
Page 3: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Topics

» What’s an affine transformation?» How to generate various forms» Things to watch out for

Page 4: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

What is it?

» A mapping between affine spaces» Preserves lines (& planes)» Preserves parallel lines» But not angles or distances» Can represent as

» (note we’re using column vectors)

T(x) Ax y

Page 5: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Affine Space

» Collection of points and vectors » Can be represented using frame

» Within frame, vector and point

j = (0,1)

O i = (1,0)

Oyx

yx

jix

jiv

Page 6: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Affine Transformation

» Key idea: map from space to space by using frames

» Note how axes change (A)» Note how origin changes (y)

T(x) Ax y

Page 7: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Example: Translation

» Axes don’t change» Origin moves by y

y

yxx )(T

Page 8: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Example: Rotation

» Axes change» Origin doesn’t move

» But what is A?

Axx )(T

Page 9: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Example: Rotation

» Follow the axes:

» New axes go in columns of matrix

(cos , sin )

(-sin , cos )

cossin

sincosA

Page 10: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Example: Scale

» Axes change» Origin doesn’t move

» Again, what is A?

Axx )(T

Page 11: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Example: Scale

» Follow the axes:

» New axes go in columns of matrix

(0, 0.5)

(1.5, 0)

5.00

05.1A

Page 12: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Example: Reflection

» Axes change» Origin doesn’t move

» But what, oh what, is A?

Axx )(T

Page 13: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Example: Reflection

» Follow the axes:

» New axes go in columns of matrix

10

01A

(-1, 0)

(0, 1)

Page 14: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Example: Shear

» Axes change» Origin doesn’t move

» Hey, hey, what is A?

Axx )(T

Page 15: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Example: Shear

» Follow the axes:

» New axes go in columns of matrix

10

5.01A

(0.5, 1)

(1, 0)

Page 16: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Transform Types

» Rigid-body transformation Translation Rotation

» Deformable transformation Scale Reflection Shear

Page 17: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Combining Transforms

» Simple function composition

zByBAx

zyAxBx

zBww

yAxx

)())((

)(

)(

TS

S

T

Page 18: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Combining Transforms

» Order is important!» Scale, then rotate

Page 19: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Combining Transforms

» Order is important!» Rotate, then scale

Page 20: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Local and World Frames

» Objects built in local frame» Want to place in world frame» Local-to-world transformation

» Same basic idea: determine where axes and origin end up in world frame

Page 21: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

World to Local Frame

» Similar, but in reverse» Want transformation relative to local

frame

» Often easier to just take the inverse» Example: world-to-view transformation

Page 22: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Inverse

» Reverses the effect of a transformation» Easy to do with formula:

» For matrix, just use matrix inverseyAzA(z)T

y)(zAx

yzAx

zyAx

111

1

Page 23: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Matrix Form

» Necessary for many APIs» Is easy

» Concatenate by matrix multiply» Can be faster on vector architectures» Takes more storage, though

Page 24: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Object-centered Transform

» Often get this case» Already have local-to-world transform

» Want rotate/scale/whatever around local origin, not world origin

» How?

Page 25: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Object-Oriented Transform

» One way» Translate to origin» Rotate there» Translate back

Page 26: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Object-Oriented Transform

» Using formula:» Translate to origin

» Rotate there

» Translate back

» This works with arbitrary center in world frame!

yz(z) T

ByBzy)B(zz ))((TS

B)y(IBzyBy)(Bzz )))((( TSR

Page 27: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Alternate Format

» Problem: want to Translate object in space and change

rotation and scale arbitrarily Handle rotation/scale separately

» Can’t do easily with matrix format or Ax + y form

» Involves SVD, Polar decomposition» Messy, but we can do better using…

Page 28: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Rigid Body Transforms

» Any sequence of translation and rotation transformations

» Not scale, reflection or shear» Object shape is not affected (preserves

angles and lengths)» Usually include uniform scale despite

this

Page 29: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Alternate Format

» Scale – one uniform scale factor s» Rotation – matrix R» Translation – single vector t

Page 30: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Alternate Format

» Want to concatenate transforms T1, T2 in this form, or

» Do this by

Page 31: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Alternate Format

» Advantages Clear what each part does Easier to change individual elements

» Disadvantages Eventually have to convert to 4x4 matrix

anyway for renderer/video card 4x4 faster on vector architecture

Page 32: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Alternate Format

» Matrix conversion

Page 33: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Inverting Rigid Body Xforms» We can easily invert our rigid body

transforms symbolically:

Page 34: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

Inverting Rigid Body Xforms (2)

» In fact, the result itself may be written as a rigid body transform:

Page 35: Affine Transformations Jim Van Verth NVIDIA Corporation (jim@essentialmath.com)jim@essentialmath.com

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.