Presentation is loading. Please wait.

Presentation is loading. Please wait.

Transformation.

Similar presentations


Presentation on theme: "Transformation."— Presentation transcript:

1 Transformation

2 Matrix column and row transpose matrix composition identity matrix
M-1 is an inverse matrix of M if MM-1=I.  1st row  2nd row  3rd row 1st column 2nd 3rd 3x2 2x3 3x3

3 Translation A transformation is a function that maps a point/vector into another point/vector. For now, we will discuss the basic 4 types of transformations: translation, scaling, rotation, and shearing. Translation ( x, y) dy (x, y) dx

4 Scaling Scaling is done about the origin.
Scale x by sx along x-axis: x = sx·x Scale y by sy along y-axis: y = sy·y The above example is called a uniform scaling where sx = sy. If sx  sy, non-uniform scaling. If 0 < sx (or sy) < 1, objects are moved closer to the origin. If sx or sy > 1, objects are moved farther from the origin. e.g. x y (6,4) x 2 4 (3,2) 2 e.g. x y (6,2) Scale by 1/2 along x Scale by 2 along y (3,4) 4

5 Reflection Reflection or mirror matrix: a scaling matrix where (sx,sy) is either (1,-1) or (–1,1). (If both sx and sy are –1, it’s a 180o rotation.) y y x x y x x y

6 Rotation Rotation by an angle  about the origin. r
The distance from P to the origin is r. Angles are measured CCW. x = r cos y = r sin x = r cos(+) = r cos cos - r sin sin = xcos - ysin y = r sin(+) = r cos sin + r sin cos = xsin + ycos For CW, you may use cos(-)=cos and sin(-)=-sin. P (x, y) r r r P(x, y)

7 Shearing Shearing along x y = y (unaffected)
x = x + ay (in the example, a  0.5) Similarly, shearing along y y x

8 Homogeneous Coordinates
Observe that rotation, scaling & shearing (which are collectively called linear transformations) are done by “matrix composition” while translation is by “vector addition.” Can we treat them uniformly? YES!! Use Homogeneous Coordinates. Practical motivations for Homogeneous Coordinates. We can treat {rotation, scaling, shearing, etc.} & {translation} uniformly. We can deal with projections (later!). A point (x, y) in Cartesian Coordinates is represented as (wx, wy, w) in Homogeneous Coordinates where w can be any non-zero value. e.g. (2 3)  ( ) = ( ) = ( ) = …... but, typically w=1.

9 Transformations in Homogeneous Coordinates
translation (x = x+dx, y = y+dy) scaling rotation shearing (along x) Note that all transformations are done by “matrix composition” thanks to homogeneous coordinates. Transformations which do not alter a body’s shape are called rigid-body transformations, and consist of rotations & translations.

10 Rotation about An Arbitrary Point
How to rotate about an arbitrary point p(x, y), not about the origin? q=(a,b) q q=(a,b) q q q q q p =(x,y) p p=O p=O translate q by -p rotate by  back-translate 3x x x3 So far, we learned translation, scaling, rotation and shearing. You have to understand that the rotation is about the origin. But suppose that we want to rotate a point about another arbitrary point. Look. We want to rotate q about p, which is not the origin. If we apply the simple rotation matrix we learned, we got a weird result because it’s about the origin. If p were the origin, we wouldn’t have any problem. Again, if p were the origin, we wouldn’t have any problem. Then, why don’t we translate p to origin and apply the same translation to q? They still maintain the relative distance and orientation. Now we can apply the famous rotation matrix because p is now at origin. Is that it? No, we have to restore the initial translation. How? Simply do back-translation with the same distance and orientation. Do we have to move p? No, p just tells me that how much q should be moved. Everything to be transformed is q. It’s translated, rotated, and back-translated. translate translate & rotate translate, rotate & back-translate Thanks to Homogeneous Coordinates, three transformations can be combined into a single 3x3 matrix.

11 Inverse Transformation
Note that the first and last translations are inverses of each other. Such an inverse transformation is represented as an inverse matrix, but can be obtained pretty easily if its geometry is considered. q q q q q q p p=O p=O translate q by -p rotate by  back-translate inverse transformations x'=x+dx x'+?=x ?=- dx

12 Inverse Transformation (cont’d)
scaling rotation shearing (along x) We have to restore y'(=y) into y and x'(=x+ay) into x, respectively. x'' = x' + ?y' = x' + ?y = x + ay + ?y = x. So, ?=-a x'=xxsx x'x?=x ?=1/sx y x

13 Associativity & Commutativity
Matrix multiplication is associative. So is transformation composition. ABC = (AB)C = A(BC) In contrast, matrix multiplication is not commutative in general. Neither is transformation composition. e.g. combination of rotation (by 90°CCW) & translation along y rotation first translation first

14 3D Translation and Scaling
First of all, Homogeneous Coordinate for 3D (x y z) → (wx wy wz w) e.g (x y z 1) Translation Scaling

15 3D Reflection Reflection or mirror matrix: a scaling matrix where one scaling factor is –1 and two others are 1 or all of the three scaling factors are –1. If two are –1, it’s a 180o rotation. reflection wrt yz-plane reflection wrt xz-plane reflection wrt xy-plane reflection wrt the origin

16 3D Rotation For 3D rotation, we need an axis of rotation.
Also, by convention, positive angles are for CCW. Recall that, in 2D, x = xcos - ysin and y = xsin + ycos. We can consider (x,y) and (x,y) as points at xy-plane of 3D space. Add z-axis and make z = z. Then, it’s 3D rotation about the z-axis. y y (x, y) (x, y) (x, y, 0) (x, y, 0) x x z y (x, y, z) (x, y, z) x z Rz(θ)

17 3D Rotation (cont’d) Rotation about x-axis
Note that the coordinate system follows the right hand rule. Let’s do cyclic permutation of the 3 axes, where the right hand rule holds. Note that rotation about x-axis is the same as rotation about the old z-axis except the permutation. For rotation about y-axis, do one more permutation! 3D shearing will be discussed when we deal with viewing. yz zx xy xyzx y' y z You have to understand that the coordinate system is right-handed. I mean, when the four fingers go from x to y, the thumb goes up along z direction. Let’s do a cyclic permutation on this right-handed coordinate system such that x becomes y, y becomes z, and then z becomes x. Look. The new coordinate systems is still right-handed. When the four fingers go from x to y, the thumb goes up along z direction. Now, we have two coordinate systems. The old black one, and the new red one. OK, let’s rotate a point around the x-axis in the red coordinate system. Then, does the x-coordinate value change? No, it does not. In the black coordinate system, z was not changed. Now, x takes the role. So, we can say x prime should be same as x. How about y and z? The red y and z are doing the same roles as the black x and y. So, we can get the rotated values y prime and z prime simply by applying cyclic permutation to the black x and y. y z' z x' x

18 Geometric Transformation of a Mesh
Apply transformations to every vertex. Geometry is transformed. Topology(connectivities) is not changed. An example, Mesh A is displayed by drawing all of its edges (wireframe display). All vertices of A are rotated, scaled up and translated to make B, and then wireframe-displayed. Use the lists demonstrated in slide 6. Topology : eo-a This is the 3rd homework. A B

19 3D Rotation about An Arbitrary Axis
z y x z by  x z Step1: Translate such that the rotation axis passes through the origin. Step2: Rotate such that the rotation axis coincides with a coordinate axis. Step3: Rotate by  y x z y x z y x z Step5: Inverse translation. (Inverse of Step1) Step4: Inverse rotation. (Inverse of Step2)

20 3D Rotation about An Arbitrary Axis (cont’d)
Rotation axis is typically defined by 2 end points p1 and p2 (or a point p and a vector v) ∴ Move p1=(x1 y1 z1) to the origin. Consider the unit vector u along the rotation axis. y y p2(x2 y2 z2) p2 (x2 y2 z2) x x p1(x1 y1 z1) p1 (x1 y1 z1) z z p2(x2 y2 z2) p2 (x2 y2 z2) unit vector u p1(x1 y1 z1) p1 (x1 y1 z1)

21 3D Rotation about An Arbitrary Axis (cont’d)
Step2 (from u to uz) requires a rather complicated process, which will be discussed soon. Just suppose the rotation is denoted by R. Step3 is simply Step4: an inverse of the matrix computed at Step2 Step5: an inverse of the matrix computed at Step1 R() is a single 4x4 matrix. y x z R u uz

22 Orthogonal Matrix Note that rotations we’ve devised are all about coordinate axes. Rotation for Step 2 is presented though orthogonal matrix. 2 rows vi & vj are orthonormal if i.e. ① each row is a unit vector, and ② any two different rows are orthogonal. Orthogonal matrix = a matrix with orthonormal rows. e.g. y x z R u uz ) ( 1 j i = orthogonal

23 Orthogonal Matrix (cont’d)
A matrix Q is orthogonal  Q·QT = I (identity matrix) Observations An orthogonal matrix transforms its rows into coordinate axes. QT = Q-1, i.e. for orthogonal matrices, the transpose is the inverse. It’s great because inverse matrix computation is usually expensive. if Q is an orthogonal matrix, QT is also an orthogonal matrix. Q-1·Q = I = QT·Q  QT·(QT)T = I  QT is orthogonal. q 1 ... q 1 1 1 e.g. q 1 ... T 1 q T 2 q ... q 2 T n q = 2 T 1 q = ... 1 ... ... ... ... ... ... ... q ... 1 q n n nxn nxn nxn nxn nx nx1

24 3D Orthogonal Matrix The same thing applies to 3D.
Suppose that we have 3 orthonormal vectors as follows. We can make orthogonal matrices using the 3 orthonormal vectors. If the 3 vectors constitute a coordinate system, i.e. the cross product of the 1st row and the 2nd row corresponds to the 3rd row following the right-hand rule, the orthogonal matrix is a rotation. uy v3 v2 ux uz v1 v1 v3 v1 v2 v1 v3 v3 v2 v2

25 3D Orthogonal Matrix (cont’d)
uy 3D rotation in homogeneous coordinates. R transforms v1, v2 and v3 into ux, uy and uz, respectively. uz v3 v2 v1 v1 v2 ‘an’ orthogonal matrix v3 ux v1 ux v3 uz v2 uy

26 3D Rotation about An Arbitrary Axis (cont’d)
Recall that, after Step1, our goal was to rotate u into uz. For this purpose, let’s make a rotation matrix whose 3rd row is u. u = v3 y x z 1 3 2 u=v v u =

27 3D Rotation about An Arbitrary Axis (cont’d)
1 3 2 u=v v u = v3 uy R = v2 x ux uz v1 z  is used to make be perpendicular to .  You can use any coordinate axis vector if it is not equal to u . Let’s simply put R into R()=T-1R-1Rz()RT. Importantly, RT is used for R-1.

28 Modeling Transformation

29 Modeling Transformation

30 Modeling Transformation
p B A r p B A r

31 Modeling Transformation
Translate by -r, bringing r to the origin. p B p B A r A A p B A p B

32 Modeling Transformation
translate both A and B by –p, bringing p to the origin. A A p B p B p B Rotate A&B Translate A p B A

33 Modeling Transformation


Download ppt "Transformation."

Similar presentations


Ads by Google