《5.二维三维的任意变换 (12)(精品).pptx》由会员分享,可在线阅读,更多相关《5.二维三维的任意变换 (12)(精品).pptx(45页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、二维三维几何变换 2D BEFORE 3DAlthough everything in real world is 3D,when we have to display something,everything reduce to a 2D image/screen spaceDrawing in 2D is therefore a basic needs Some concepts and maths are easier to understand in 2D before going into 3D二维变换Common operations on 2D shapes include Sc
2、aling(放缩)Rotation(旋转)Translation(平移)用矩阵来表示二维变换In general,a matrix is a rectangular array of elements(usually numbers or values)It can be any size Vector in Matrix FormAs a special case that a 2D vector is put into a matrix of 2 x 1 like 单位矩阵和转置矩阵Identity MatrixA special matrix which have no effect i
3、n matrix multiplicationTransposeChange row to column,column to rowE.g.here matrix MT is the transpose of matrix MTranspose二维放缩Scale Matrix,sx and sy are the scaling factor in x and y directionsWhen multiplying with a vertex二维放缩一致放缩和差值放缩放缩但保持原来的位置方缩+平移二维放缩An example to shrink half the size:So,every v
4、ertices are multiplying this matrix二维旋转2D Rotation commonly involves Reference pointAngle of rotationUsually,it is easiest to use the origin(0,0)origin(0,0)as the reference pointThe related equations:anti-clockwise二维旋转So,the Rotation MatrixA rotation with 45 degrees(PI/4)in anticlockwise二维旋转绕任意基准点旋转
5、旋转+平移二维平移Move horizontally(in x axis)or vertically(in y axis)E.g.move 3 units to right in x,4 units up in y43Translation齐次坐标If only 2x2 matrix is used,it is not possible to represent translation with a Matrix multiplication similar to what rotation and scaling doesTo let also translation to be done
6、using only Matrix multiplication,we will talk about Homogeneous coordinate in the next lesson为什么要用齐次坐标按顺序多次几何变换P=M1P+M2消除矩阵加法 齐次坐标下的二维几何变换表示按列表示二维平移矩阵二维旋转矩阵二维放缩矩阵复合变换矩阵MULTIPLE 2D TRANSFORMATIONSHow about the case we want to do more than one transformation the same time?For example,First,shrink in Y
7、 direction for 0.5(Matrix S)Then,rotate 45 degree in anticlockwise(Matrix R)If we represent in Matrix form,the above complex operation can also be represented in a matrix MMULTIPLE 2D TRANSFORMATIONSThis Matrix M is formed by multiplying Matrices S and R,becauseApplying transform matrices in sequenc
8、e is the same as applying the product of those matricesSRM=SRORDER OF APPLYING TRANSFORMATIONSAnother question,does M=SR=RS?The order of multiplication a matter?From the example on right,we know that SR=RSSo be-careful,Order DOESDOES Matter!ORDER OF APPLYING TRANSFORMATIONSWe can also show the relat
9、ed Matrices formed:RS=M1 SR=M2They are different!They are different!通用二维基准点旋转与放缩通用二维基准点旋转平移对象使基准点位置移动到坐标原点绕坐标原点旋转平移对象使基准点回到原始位置通用二维基准点放缩平移对象使固定点与坐标原点重合对于坐标原点进行放缩使用步骤一反向平移将对象返回原点位置几个常用概念刚体变换仅包含平移和旋转参数放射变换(9.7节)平移放缩旋转反射错切DOES MATRIX REALLY NECESSARY?The answer is Yes or NoNo:You can do computation in
10、sets of equationsYes:It sometimes make things more clear and easyYes:We can think any kind of transformation(including S,R,T or etc)to be represented with matrix and performed by a multiplication in matrixYes:It is already a standard and common language in GraphicsSUMMARYAn overview of computer grap
11、hics topicsBasic 2D geometry:Vertex,Line,Triangle and etc.Mathematics of Vector,Matrix using 2D examples2D Transformations:scaling,rotation and translationRelation between transformation and matrix multiplication3D TRANSLATIONThe translation can be represented in 4 x 4 matrix T in homogeneous coordi
12、nates:T=Here t=is the direction and magnitude of movet tIdentity Matrix3D TRANSLATIONt t3D SCALINGScale Matrix is a direct extension to its 2D version,Now,we have sx,sy and sz as the scaling factor in x,y and z directions3D SCALING3D SCALINGNotice that the scaling is in reference to the origin(0,0,0
13、)If objects center is not at origin,a direct multiply with the scale matrix will look like moving the object at the same time A simple solution is to first translate the object to the origin,scale and then translate back to the original centerMULTIPLE 3D TRANSFORMATIONSBefore discussing the solution
14、,recall the topic about multiple transformation in last lessonTo apply more than one transformation,e.g.First,shrink in Y direction for 0.5(Matrix S)Then,rotate 45 degree in anticlockwise(Matrix R)The standard way is do it stepwise,but it is the same as we multiply RS to the vertexSRM=SRTo scale acc
15、ording to object center,we need to multiply with translation matrix T,then scale translation matrix S and finally inverse of T (i.e.T-1)T-1STNote the translation is to move the object center to origin3D SCALINGTST-1INVERSE MATRIXBy definition,inverse matrix A-1of a matrix A should satisfy:A-1 A=II i
16、s an identity matrixthat is they cancel out each others effect The computation of inverse matrix is a bit involving,and had several ways to do,please check your textbook or books of linear algebra for detailsINVERSE MATRIX3D ROTATIONZ-axisSame as 2D rotation3D ROTATIONSimilarly we can rotate about x
17、 and y axisY-axisX-axis3D ROTATION=ORDER OF APPLYING TRANSFORMATIONSSimilar to 2D,order of applying transformation in 3D DOES MatterE.g.we know that SR=RSSo be-careful,Order DOESDOES Matter!COORDINATE SYSTEMWhen talking about coordinate system,we will need to know our referenceAny point will have di
18、fferent coordinates if our coordinate system are different E.g.we see a certain position on the Earth or on MoonThey will both think they are the origin!The EarthThe MoonIm the center(1,10,1)?(2,4,6)?COORDINATE SYSTEMIn 3D,the coordinate frame are formed by 3 basis vectors(unit vector is used)They a
19、re suppose to be perpendicular to each otherE.g.vx,vy,vzA vector defined by this basis is written as v=a vx+bvy+cvzSo,the coordinate becomes (a,b,c)in this framevxvyvzCOORDINATE SYSTEMSo the conventional x,y,z axis becomes a particular case in whichvx=vy=vz=Notice that all of them are unit vectors3D
20、 ROTATION ABOUT ARBITRARY AXISa3D ROTATION ABOUT ARBITRARY AXISSo,the method has 3 stepsTransform the vertex to the new coordinate frameRotate Transform back to original coordinate frameMRM-1aa3D ROTATION ABOUT ARBITRARY AXISE.g.To rotate about the vector about 45 degree anticlockwise M=R=M-1=Obtain
21、ed by cross product with y-axisObtained by cross product betweenthe above 2 vectorsTRANSFORMING SPACE WITH HOMOGENOUS COORDINATEIn the last 3x3 matrix,the transformation between coordinate frame does not allow translations to happenNow,we have M as a 4x4 matrix:We are not discuss in full detail here
22、,please refer to your textbookM=OTHER COMMON TRANSFORMATIONSShear:equivalent to pulling faces in opposite directionsReflection:inverted in horizontal or vertical directionSUMMARYStudied the 3D coordinate system and related mathematics3D vector,matrix and transformationHomogeneous coordinate is commonly usedThe change of coordinate system can also be achieved by matrix multiplication