Transcription of Lecture 3: Coordinate Systems and Transformations
1 Lecture3:CoordinateSystemsandTransformat ionsTopics:1. Coordinatesystemsandframes2. Changeof frames3. A netransformations4. Rotation,translation,scaling,andshear5. RotationaboutanarbitraryaxisChapter4, , , , , , vectorv2lR3canbe representedas a linearcombinationofthreelinearlyindepend ent basisvectorsv1,v2,v3,v= 1v1+ 2v2+ 3v3:Thescalars 1, 2, 3arethecoordinatesofv. We typicallychoosev1= (1;0;0),v2= (0;1;0),v3= (0;0;1) .v2v1v3 1v = 1v1 + 2v2 + 3v32 Supposewe want to (linearly)changethebasisvectorsv1,v2,v3t ou1,u2,u3. We expressthenewbasisvectorsas combinationsof theoldones,u1=a11v1+a12v2+a13v3;u2=a21v1 +a22v2+a23v3;u3=a31v1+a32v2+a33v3;andthu s obtaina 3 3 `changeof basis'matrixM=0@a11a12a13a21a22a23a31a32 a331A:If thetwo representationsof a givenvectorvarev=aT0@v1v2v31A;andv=bT0@u 1u2u31A;wherea= ( 1 2 3)Tandb= ( 1 2 3)T, thenaT0@v1v2v31A=v=bT0@u1u2u31A=bTM0@v1v 2v31A;which impliesthata=MTbandb= (MT) 1a:3 This3 Dcoordinatesystemis not,however,rich enoughforusein usedto rotateandscalevectors,it cannotdealwithpoints, andwe want to be abletotranslatepoints(andobjects).
2 In factanarbitarya netransformationcanbe achieved by multiplicationby a 3 3 matrixandshiftby a ,in computergraphicswepreferto useframesto achieve a richercoordinatesystemin which we have a referencepointP0in additionto threelinearlyindependent basisvectorsv1,v2,v3, andwerepresent vectorsvandpointsP, di erently, asv= 1v1+ 2v2+ 3v3;P=P0+ 1v1+ 2v2+ 3v3:We canusevectorandmatrixnotationandre-expre ssthevectorvandpointPasv= ( 1 2 30 )0B@v1v2v3P01CA;andP= ( 1 2 31 )0B@v1v2v3P01CA:Thecoe cients 1; 2; 3;0 and 1; 2; 3;1 framesSupposewe want to changefromtheframe(v1; v2; v3; P0) to a newframe(u1; u2; u3; Q0).We expressthenewbasisvectorsandreferencepoi nt intermsof theoldones,u1=a11v1+a12v2+a13v3;u2=a21v1 +a22v2+a23v3;u3=a31v1+a32v2+a33v3;Q0=a41 v1+a42v2+a43v3+P0;andthus obtaina 4 4 matrixM=0B@a11a12a130a21a22a230a31a32a33 0a41a42a4311CA:Similarto 3 Dvectorcoordinates,we supposenow thataandbarethehomogeneousrepresentation sof thesamepoint or vectorwithrespecttothetwo @v1v2v3P01CA=bT0B@u1u2u3Q01CA=bTM0B@v1v2 v3P01CA;which impliesthata=MTbandb= (MT) 1a:5A netransformationsThetransposedmatrixMT=0 B@a11a21a31a41a12a22a32a42a13a23a33a4300 011CA.
3 Simplyrepresents anarbitrarya netransformation, having12degreesof freedomcanbe viewedas thenineelementsof a 3 3 matrixplusthethreecomponents of a a netransformationsarerotations,scalings,a ndtranslations, andin factalla netransformationscanbe expressedas combinaitonsof netransformationspreserve a linesegmentP( ) = (1 )P0+ P1is expressedin homogeneouscoordinatesasp( ) = (1 )p0+ p1;withrespectto someframe,thenana netransformationmatrixMsendsthelinesegme ntPinto thenewone,Mp( ) = (1 )Mp0+ Mp1:Similarly, a netransformationsmaptrianglesto trianglesandtetrahedrato many objectsin OpenGLcanbe transformedby ,translation,scaling,andshearTranslation is anoperationthatdisplacespoints by a xeddistancein thedisplacement vectorisdthenthepointPwillbemovedtoP0=P+ d:We canwritethisequationin homeogeneouscoordinatesasp0=p+d;wherep=0 B@xyz11CA;p0=0B@x0y0z011CA;d=0B@ x y z01CA:so thatx0=x+ x;y0=y+ y;z0=z+ z:SothetransformationmatrixTwhich givesp0=Tpis clearlyT=T( x; y; z) =0B@100 x010 y001 z00011CA;calledthetranslationmatrix.
4 Onecancheck thattheinverseisT 1( x; y; z) =T( x; y; z):7 Rotationdependsonanaxisof rstrotationin theplane, a point (x; y) withcoordinatesx= cos ;y= sin ;is rotatedthroughanangle , thenthenewpositionis (x0; y0), wherex0= cos( + );y0= sin( + ):Expandingtheselatterexpressions,we ndx0=xcos ysin ;y0=xsin +ycos ;or x0y0 = cos sin sin cos xy :xyxy8 Thus thethreerotationmatricescorrespondingto rotationaboutthez,x,andyaxesin lR3are:Rz=Rz( ) =0B@cos sin 00sin cos 00001000011CA;Rx=Rx( ) =0B@10000cos sin 00sin cos 000011CA;Ry=Ry( ) =0B@cos 0sin 00100 sin 0cos 000011CA:Allthreegive positive rotationsforpositive withrespecttotherighthandrulefortheaxesx ; y; z. IfR=R( ) denotesany of thesematrices,itsinverseis clearlyR 1( ) =R( ) =RT( ):Translationsandrotationsareexamplesofs olid-bodytransforma-tions: transformationswhich donotalterthesizeor shape of appliedin any of thethreeaxesindependently.
5 If we senda point (x; y; z) to thenewpointx0= xx;y0= yy;z0= zz;thenthecorrespondingmatrixbecomesS=S( x; y; z) =0B@ x0000 y0000 z000011CA;withinverseS 1( x; y; z) =S(1= x;1= y;1= z):If thescalingfactors x; y; zareequalthenthescalingisuniform:objects retaintheirshape constructedfromtranslations,rotations,an dscalings,butaresometimesof independent shearin thexdirectionis de nedbyx0=x+ (cot )y;y0=y;z0=z;forsomescalara. Thecorrespondingshearingmatrixis thereforeHx( ) =0B@1cot 000100001000011CA;withinverseH 1x( ) =Hx( ):11 RotationaboutanarbitraryaxisHow do we ndthematrixwhich rotatesan objectaboutan arbitrarypointp0andarounda directionu=p2 p1, throughanangle ?xyz p0p1p2uTheanswer is to concatenatesomeof thematriceswe have rststepis to usetranslationto reducetheproblemto thatof rotationabouttheorigin:M=T(p0)R T( p0):To ndtherotationmatrixRforrotationaroundthe vectoru, we rstalignuwiththezaxisusingtwo rotations xand y.
6 Thenwe canapplya rotationof aroundthez-axisandafterwardsundothealign ments,thusR=Rx( x)Ry( y)Rz( )Ry( y)Rx( x):12It remainsto calculate xand yfromu= ( x; y; z). The rstrotationRx( x) willrotatethevectoruaroundthexaxisuntil it liesin they= , we ndthatcos x= z=d;sin x= y=d;whered=q 2y+ 2z, so,withoutneeding xexplicitly, we ndRx( x) =0B@10000 z=d y=d00 y=d z=d000011CA:In thesecondalignment we ndcos y=d;sin y= x;andsoRy( y) =0B@d0 x00100 x0d000011CA:13 Examplein OpenGLThefollowingOpenGLsequencesetsthem odel-viewmatrixto represent a45-degreerotationaboutthelinethroughthe originandthepoint (1;2;3)witha xedpoint of (4;5;6):voidmyinit(void){glMatrixMode(GL _MODELVIEW);glLoadIdentity();glTranslate f( , , );glRotatef( , , , );glTranslatef( , , );}OpenGLconcatenatesthethreematricesint o thesinglematrixC=T(4;5;6)R(45;1;2;3)T( 4; 5.)
7 6):Each vertexpspeci edafterthiscodewillbe multipliedbyCto yieldq,q=Cp:14 SpinningtheCubeThefollowingprogramrotate sa cube, usingthethreebuttonsof :glutDisplayFunc(display);glutIdleFunc(s pincube);glutMouseFunc(mouse);Thedisplay callback setsthemodel-viewmatrixwiththreeanglesde ter-minedby themousecallback, andthendrawsthecube ( ).voiddisplay(){glClear(GL_COLOR_BUFFER_ BITGL_DEPTH_BUFFER_BIT);glLoadIdentity() ;glRotatef(theta[0], , , );glRotatef(theta[1], , , );glRotatef(theta[2], , , );colorcube();glutSwapBuffers();}15 Themousecallback selectstheaxisof (intbtn,intstate,int x, int y){if(btn== GLUT_LEFT_BUTTON&& state== GLUT_DOWN)axis= 0;if(btn== GLUT_MIDDLE_BUTTON&& state== GLUT_DOWN)axis= 1;if(btn== GLUT_RIGHT_BUTTON&& state== GLUT_DOWN)axis= 2;}Theidlecallback increments theangleof thechosenaxisby 2 (){theta[axis]+= ;if(theta[axis]>= )theta[axis]-= ;glutPostRedisplay().}
8 }16A littlebitaboutquarternionsQuarternionso eran alternative way of describingrotations,andhave beenusedin thecomplexplane,rotationthroughanangle canbe expressedasmultiplicationby thecomplexnumberei = cos +isin :Thisrotatesa givenpointrei in thecomplexplaneto thenewpointrei ei =rei( + ):Analogously, quarternionscanbe usedtoelegantlydescribe a scalaranda vector,a= (q0; q1; q2; q3) = (q0;q):We canwritethevectorpartqasq=q1i+q2j+q3k;wh erei,j,kplay a similarroleto thatof theunitvectorsin lR3, andobeythepropertiesi2=j2=k2= 1;andij=k= ji;jk=i= kj;ki=j= ik:17 Thesepropertiesimplythatthesumandmultipl eof two quarternionsa=(q0;q) andb= (p0;p) area+b= (q0+p0;q+p);andab= (q0p0 q p; q0p+p0q+q p):Themagnitudeandinverseofaarejaj=qq20+ q q;a 1=1jaj(q0; q):Rotation. Supposenow thatvis a unitvectorin lR3, andletpbe anarbitrarypoint.
9 Denotebyp0therotationofpabouttheaxisv, ndp0usingquarternions,we letrbe thequarterionr= (cos( =2);sin( =2)v);of unitlength,whoseinverseis clearlyr 1= (cos( =2); sin( =2)v):Thenifpandp0arethequarternionsp= (0;p);p0= (0;p0);we claimthatp0=r 1pr:18 Let'scheck thatthisis correct!Followingtheruleformultiplicatio n,a littlecomputationshowsthatp0does indeedhave theform(0;p0), andthatp0= cos2 2p+ sin2 2(v p)v+ 2 sin 2cos 2(v p) + sin2 2v (v p):Butusingtheidentityp= (v p)v v (v p);(1)andthemultiple-angleformulasforcos andsin, thissimpli estop0= (v p)v+ cos (v p) v+ sin (v p):Thisformulacaneasilybe veri edfroma isa linearcombinationof rstterm(v p)vis theprojectionofponto theaxisof rotation,andthesecondandthirdtermsdescri be a rotationin an a netransformation;alltermsarelinearinp. Theformulacanbe usedto ndthecoe cientsof