CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine,...

Preview:

Citation preview

CMSC427TransformationsI

Credit:slides9+fromProf.Zwicker

• Typesoftransformations• Specific:translation,rotation,scaling,shearing• Classes:rigid,affine,projective

• Representingtransformations• Unifyingrepresentationwithhomogeneouscoordinates• Transformationsrepresentedasmatrices

• Composingtransformations• Sequencingmatrices• SequencingusingOpenGLstackmodel

• Transformationexamples• Rotatingorscalingaboutapoint• Rotatingtoanewcoordinateframe

• Applications• Modelingtransformations(NOW)• Viewingtransformations(LATER)

Transformations: outline

• Createinstanceofobjectinobjectcoordinatespace• Createcircleatorigin

• Transformobjecttoworldcoordinatespace• Scaleby1.5• Movedownby2unit

• Dosoforotherobjects• Tworects makehat• Threecirclesmakebody• Twolinesmakearms

• Objectcoordinatespace

• Worldcoordinatespace

Modeling with transformations

• Rigid• Translate,rotate,uniformscale• Nodistortiontoobject

• Affine• Translate,rotate,scale(non-uniform),shear,reflect• Limiteddistortions• Preserveparallellines

Classes of transformations

• Affine• Preservesparallellines

• Projective• Foreshortens• Linesconverge• Forviewing/rendering

Classes of transformations

• Affine• Reshape,sizeobject

• Rigid• Place,moveobject

• Projective• Viewobject• Later…

• Non-linear,arbitrary• Twists,pinches,pulls• Notinthisunit

Classes of transformations: summary

• ScaleapointpbysandtranslatebyT• Vectormultiplicationandaddition• Repeatandweget

• Getsunwieldy• Instead– unifynotationwithhomogeneouscoordinatesandmatrices

First try: scale and rotate vertices in vector notation

𝑞 = 𝑠 ∗ 𝑝 + 𝑇

T

p

q

𝑞 = 𝑠( 𝑠 ∗ 𝑝 + 𝑇 + 𝑇(

𝑞 = 2 ∗ 2,3 +< 2,2 >𝑞 = (6,8)

Matrix practice

𝑀 = 2 00 2

𝑅 = 1 10 3

𝑃 = 23

𝑀𝑅 = 2 00 2 1 1

0 3 =

𝑅𝑀 = 1 10 3

2 00 2 =

𝑀𝑃 = 2 00 2 23 =

Matrix practice

𝑀 = 2 01 2

𝑅 = 1 10 3

𝑃 = 23

𝑀𝑅 = 2 01 2 1 1

0 3 = 2 71 6

𝑅𝑀 = 1 10 3

2 01 2 = 3 2

3 6

𝑀𝑃 = 2 01 2 23 = 4

8

Matrix transpose and column vectors

𝑃 = 23 = 2 3 9

𝑅9 = 1 10 3

9=

𝐻9 = 2 1 34 1 5

9=

Matrix transpose and column vectors

𝑃 = 23 = 2 3 9

𝑅9 = 1 10 3

9= 1 0

1 3

𝐻9 = 2 1 34 1 5

9=

2 41 13 5

Matrices

Abstractpointofview• Mathematicalobjectswithsetofoperations• Addition,subtraction,multiplication,multiplicativeinverse,etc.

• Similartointegers,realnumbers,etc.But• Propertiesofoperationsaredifferent• E.g.,multiplicationisnotcommutative

• Representdifferentintuitiveconcepts• Scalarnumbersrepresentdistances• Matrices canrepresentcoordinatesystems,rigidmotions,in3Dandhigherdimensions,etc.

12

Matrices

Practicalpointofview• Rectangulararrayofnumbers

• Squarematrixif• Ingraphicsoften

13

Matrix addition

14

Multiplication with scalar

15

Matrix multiplication

16

Matrix multiplication

17

Matrix multiplication

18

Matrix multiplication

19

Matrix multiplication

Specialcase:matrix-vectormultiplication

20

Linearity

• Distributivelawholds

i.e.,matrixmultiplicationislinearhttp://en.wikipedia.org/wiki/Linear_map

• Butmultiplicationisnotcommutative,

ingeneral

21

Identity matrix

22

Matrix inverse

DefinitionIfasquarematrixisnon-singular,thereexistsauniqueinverse suchthat

• Note

• Computation• Gaussianelimination,Cramer’srule(OctaveOnline)• Reviewinyourlinearalgebrabook,orquicksummary

http://www.maths.surrey.ac.uk/explore/emmaspages/option1.html

23

Java vs. OpenGL matrices

• OpenGL(underlying3DgraphicsAPIusedintheJavacode,morelater)http://en.wikipedia.org/wiki/OpenGL

• Matrixelementsstoredinarrayoffloatsfloat M[16];• “Columnmajor”ordering

• Javabasecode• “Rowmajor”indexing• ConversionfromJavatoOpenGLconventionhiddensomewhereinbasecode!

24

Today

Transformations&matrices• Introduction• Matrices• Homogeneouscoordinates• Affinetransformations• Concatenatingtransformations• Changeofcoordinates• Commoncoordinatesystems

25

Vectors & coordinate systems

• Vectorsdefinedbyorientation,length• Describeusingthreebasisvectors

26

Points in 3D

• Howdowerepresent3Dpoints?• Arethreebasisvectorsenoughtodefinethelocationofapoint?

27

Points in 3D

• Describeusingthreebasisvectorsand referencepoint,origin

28

Vectors vs. points

• Vectors

• Points

• Representationofvectorsandpointsusing4th coordinateiscalledhomogeneouscoordinates

29

Homogeneous coordinates

• Representanaffinespacehttp://en.wikipedia.org/wiki/Affine_space

• Intuitivedefinition• Affinespacesconsistofavectorspaceandasetofpoints• Thereisasubtraction operationthattakestwopointsandreturnsavector• AxiomI:foranypointa andvectorv,thereexistspoint

b,suchthat(b-a) = v• AxiomII:foranypointsa, b, c wehave

(b-a)+(c-b) = c-a

30

Affine space

Vectorspace,http://en.wikipedia.org/wiki/Vector_space

• [xyz]coordinates• representsvectors

Affinespacehttp://en.wikipedia.org/wiki/Affine_space

• [xyz1],[xyz0]homogeneouscoordinates• distinguishespointsandvectors

31

Homogeneous coordinates

• Subtractionoftwopointsyieldsavector

• Usinghomogeneouscoordinates

32

Today

Transformations&matrices• Introduction• Matrices• Homogeneouscoordinates• Affinetransformations• Concatenatingtransformations• Changeofcoordinates• Commoncoordinatesystems

33

Affine transformations

• Transformation,ormapping:functionthatmapseach3Dpointtoanew3Dpoint„f: R3 -> R3“• Affinetransformations:classoftransformationstoposition3Dobjectsinspace• Affinetransformationsinclude• Rigidtransformations

• Rotation• Translation

• Non-rigidtransformations• Scaling• Shearing

34

Affine transformations

• Definition:mappings that preserve colinearity andratios of distanceshttp://en.wikipedia.org/wiki/Affine_transformation

• Straightlines are preserved• Parallellines are preserved

• Lineartransformations +translation• Nice:Alldesired transformations (translation,rotation)implemented using homogeneouscoordinates and matrix-vector multiplication

35

Translation

Point Vector

36

Matrix formulation

Point Vector

37

Matrix formulation

• Inverse translation

• Verify that

38

Note

• Whathappenswhenyoutranslateavector?

39

Rotation

First:rotatingavectorin2D• Convention:positiveanglerotatescounterclockwise• Expressusingrotationmatrix

40

Rotating a vector in 2D

41

Rotating a vector in 2D

42

Rotating a vector in 2D

43

Rotation in 3D

Rotationaroundz-axis• z-coordinatedoesnotchange

• Whatisthematrixfor?

v0= R z(µ)v

44

Other coordinate axes

• Samematrixtorotatepointsandvectors• Pointsarerotatedaroundorigin

45

Rotation in 3D

• Concatenaterotationsaroundx,y,z axestoobtainrotationaroundarbitraryaxesthroughorigin

• arecalledEulerangleshttp://en.wikipedia.org/wiki/Euler_angles

• Disadvantage:resultdependsonorder!

46

Gimbalhttps://en.wikipedia.org/wiki/Gimbal

Rotation around arbitrary axis

• Still:origindoesnotchange• Counterclockwiserotation• Angle,unitaxis•

• Intuitivederivationseehttp://mathworld.wolfram.com/RotationFormula.html

47

Summary

• Differentwaystodescriberotationsmathematically• Sequenceofrotationsaroundthreeaxes(Eulerangles)• Rotationaroundarbitraryangles(axis-anglerepresentation)• Otheroptionsexist(quaternions,etc.)

• Rotationspreserve• Angles• Lengths• Handednessofcoordinatesystem

• Rigidtransforms• Rotationsandtranslations

48

Rotation matrices

• Orthonormal• Rows,columnsareunitlengthandorthogonal

• Inverseofrotationmatrix?

49

Rotation matrices

• Orthonormal• Rows,columnsareunitlengthandorthogonal

• Inverseofrotationmatrix?• Itstranspose

50

Rotations

• Givenarotationmatrix• Howdoweobtain ?

51

Rotations

• Givenarotationmatrix• Howdoweobtain ?

52

Rotations

• Givenarotationmatrix• Howdoweobtain ?

• Howdoweobtain …?

53

Rotations

• Givenarotationmatrix• Howdoweobtain ?

• Howdoweobtain …?

54

Scaling

• Origin does not change

55

Scaling

• Inversescaling?

56

Scaling

• Inversescaling?

57

Shear

• Pureshearifonlyoneparameterisnon-zero• Cartoon-likeeffects

58

Summary affine transformations

• Lineartransformations(rotation,scale,shear,reflection)+translation

Vectorspace,http://en.wikipedia.org/wiki/Vector_space

• vectorsas[xyz]coordinates• representsvectors• lineartransformations

Affinespacehttp://en.wikipedia.org/wiki/Affine_space

• pointsandvectorsas[xyz1],[xyz0]homogeneouscoordinates• distinguishespointsandvectors• lineartranforms andtranslation

59

Summary affine transformations

• Implementedusing4x4matrices,homogeneouscoordinates• Lastrowof4x4matrixisalways[0 0 0 1]

• Anysuchmatrixrepresentsanaffinetransformationin3D• Factorizationintoscale,shear,rotation,etc.isalwayspossible,butnon-trivial• Polardecomposition

http://en.wikipedia.org/wiki/Polar_decomposition

60

Today

Transformations&matrices• Introduction• Matrices• Homogeneouscoordinates• Affinetransformations• Concatenatingtransformations• Changeofcoordinates• Commoncoordinatesystems

61

Concatenating transformations

• Build“chains”oftransformations

• Applyfollowedbyfollowedby

• Overalltransformationisanaffinetransformation

• Multiplicationontheleft

62

Concatenating transformations

• Resultdependsonorderbecausematrixmultiplicationnotcommutative• Thoughtexperiment• Translationfollowedbyrotationvs.rotationfollowedbytranslation

63

Rotating with pivot

Rotation around origin

Rotation with pivot

64

1. Translation 2. Rotation 3. Translation

Rotating with pivot

65

Rotating with pivot

1. Translation 2. Rotation 3. Translation

66

Concatenating transformations

• Arbitrarysequenceoftransformations

• Note:associativity

SoeitherisvalidT=M3.multiply(M2); Mtotal=T.multiply(M1)orT=M2.multiply(M1); Mtotal=M3.multiply(T)

67

• Transformationsareusedformodeling• Classesoftransformation:rigidandaffine• Whyweusehomo.coordinatesandmatrices• Howtodomatrixmults,inversion,transpose• Homogenouscoordinates,vectorsvs.points• Propertiesofaffinetransformations• Transforms:translation,scale,rotation,shear• Onlystartingwith3Drotations– don’tbeconcerned

• Orderoftransformations• Theydon’tcommute,butareassociative• Translatetooriginforscaling,rotation

Transformation: summary

Recommended