68
CMSC427 Transformations I Credit: slides 9+ from Prof. Zwicker

CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

CMSC427TransformationsI

Credit:slides9+fromProf.Zwicker

Page 2: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

• 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

Page 3: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

• Createinstanceofobjectinobjectcoordinatespace• Createcircleatorigin

• Transformobjecttoworldcoordinatespace• Scaleby1.5• Movedownby2unit

• Dosoforotherobjects• Tworects makehat• Threecirclesmakebody• Twolinesmakearms

• Objectcoordinatespace

• Worldcoordinatespace

Modeling with transformations

Page 4: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

• Rigid• Translate,rotate,uniformscale• Nodistortiontoobject

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

Classes of transformations

Page 5: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

• Affine• Preservesparallellines

• Projective• Foreshortens• Linesconverge• Forviewing/rendering

Classes of transformations

Page 6: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

• Affine• Reshape,sizeobject

• Rigid• Place,moveobject

• Projective• Viewobject• Later…

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

Classes of transformations: summary

Page 7: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

• 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)

Page 8: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

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 =

Page 9: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

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

Page 10: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Matrix transpose and column vectors

𝑃 = 23 = 2 3 9

𝑅9 = 1 10 3

9=

𝐻9 = 2 1 34 1 5

9=

Page 11: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

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

Page 12: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Matrices

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

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

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

12

Page 13: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Matrices

Practicalpointofview• Rectangulararrayofnumbers

• Squarematrixif• Ingraphicsoften

13

Page 14: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Matrix addition

14

Page 15: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Multiplication with scalar

15

Page 16: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Matrix multiplication

16

Page 17: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Matrix multiplication

17

Page 18: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Matrix multiplication

18

Page 19: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Matrix multiplication

19

Page 20: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Matrix multiplication

Specialcase:matrix-vectormultiplication

20

Page 21: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Linearity

• Distributivelawholds

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

• Butmultiplicationisnotcommutative,

ingeneral

21

Page 22: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Identity matrix

22

Page 23: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

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

Page 24: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Java vs. OpenGL matrices

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

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

• Javabasecode• “Rowmajor”indexing• ConversionfromJavatoOpenGLconventionhiddensomewhereinbasecode!

24

Page 25: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Today

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

25

Page 26: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Vectors & coordinate systems

• Vectorsdefinedbyorientation,length• Describeusingthreebasisvectors

26

Page 27: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Points in 3D

• Howdowerepresent3Dpoints?• Arethreebasisvectorsenoughtodefinethelocationofapoint?

27

Page 28: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Points in 3D

• Describeusingthreebasisvectorsand referencepoint,origin

28

Page 29: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Vectors vs. points

• Vectors

• Points

• Representationofvectorsandpointsusing4th coordinateiscalledhomogeneouscoordinates

29

Page 30: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

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

Page 31: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

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

Page 32: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Homogeneous coordinates

• Subtractionoftwopointsyieldsavector

• Usinghomogeneouscoordinates

32

Page 33: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Today

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

33

Page 34: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Affine transformations

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

• Rotation• Translation

• Non-rigidtransformations• Scaling• Shearing

34

Page 35: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

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

Page 36: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Translation

Point Vector

36

Page 37: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Matrix formulation

Point Vector

37

Page 38: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Matrix formulation

• Inverse translation

• Verify that

38

Page 39: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Note

• Whathappenswhenyoutranslateavector?

39

Page 40: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Rotation

First:rotatingavectorin2D• Convention:positiveanglerotatescounterclockwise• Expressusingrotationmatrix

40

Page 41: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Rotating a vector in 2D

41

Page 42: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Rotating a vector in 2D

42

Page 43: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Rotating a vector in 2D

43

Page 44: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Rotation in 3D

Rotationaroundz-axis• z-coordinatedoesnotchange

• Whatisthematrixfor?

v0= R z(µ)v

44

Page 45: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Other coordinate axes

• Samematrixtorotatepointsandvectors• Pointsarerotatedaroundorigin

45

Page 46: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Rotation in 3D

• Concatenaterotationsaroundx,y,z axestoobtainrotationaroundarbitraryaxesthroughorigin

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

• Disadvantage:resultdependsonorder!

46

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

Page 47: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Rotation around arbitrary axis

• Still:origindoesnotchange• Counterclockwiserotation• Angle,unitaxis•

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

47

Page 48: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Summary

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

• Rotationspreserve• Angles• Lengths• Handednessofcoordinatesystem

• Rigidtransforms• Rotationsandtranslations

48

Page 49: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Rotation matrices

• Orthonormal• Rows,columnsareunitlengthandorthogonal

• Inverseofrotationmatrix?

49

Page 50: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Rotation matrices

• Orthonormal• Rows,columnsareunitlengthandorthogonal

• Inverseofrotationmatrix?• Itstranspose

50

Page 51: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Rotations

• Givenarotationmatrix• Howdoweobtain ?

51

Page 52: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Rotations

• Givenarotationmatrix• Howdoweobtain ?

52

Page 53: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Rotations

• Givenarotationmatrix• Howdoweobtain ?

• Howdoweobtain …?

53

Page 54: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Rotations

• Givenarotationmatrix• Howdoweobtain ?

• Howdoweobtain …?

54

Page 55: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Scaling

• Origin does not change

55

Page 56: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Scaling

• Inversescaling?

56

Page 57: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Scaling

• Inversescaling?

57

Page 58: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Shear

• Pureshearifonlyoneparameterisnon-zero• Cartoon-likeeffects

58

Page 59: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

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

Page 60: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

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

Page 61: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Today

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

61

Page 62: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Concatenating transformations

• Build“chains”oftransformations

• Applyfollowedbyfollowedby

• Overalltransformationisanaffinetransformation

• Multiplicationontheleft

62

Page 63: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Concatenating transformations

• Resultdependsonorderbecausematrixmultiplicationnotcommutative• Thoughtexperiment• Translationfollowedbyrotationvs.rotationfollowedbytranslation

63

Page 64: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Rotating with pivot

Rotation around origin

Rotation with pivot

64

Page 65: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

1. Translation 2. Rotation 3. Translation

Rotating with pivot

65

Page 66: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Rotating with pivot

1. Translation 2. Rotation 3. Translation

66

Page 67: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

Concatenating transformations

• Arbitrarysequenceoftransformations

• Note:associativity

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

67

Page 68: CMSC427 Transformations Ireastman/slides/L05P1Transformations.pdf · •Classes: rigid, affine, projective •Representing transformations •Unifying representation with homogeneous

• 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