Supot37255412160

  • 510 views
Uploaded on

 

More in: Business , Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
510
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Chapter 5 Geometric Transformations
  • 2. 5.1 Basic Two-Dimensional Geometric Transformations Operations that are applied to the geometric description of an object to change its position, orientation, or size are called geometric transformations. Geometric transformations can be used to describe how objects might move around in a scene during an animation sequence or simply to view them from another angle.
  • 3.  geometric transformations  Translation  Rotation  Scaling
  • 4. Two-Dimensional Translation We perform a translation on a single coordinate point by adding offsets to its coordinates so as to generate a new coordinate position. To translate a two-dimensional position, we add translation distances, tx and ty to the original coordinates (x,y) to obtain the new coordinate position (x’,y’), x = x+t x y = y + ty
  • 5. The two-dimensional translation equations in the matrix form จาก x = x + tx ให้ รูป y y = y + ty x  P=  x  P =   P ( x , y )  y y    T t x  ty และ T = P ( x, y ) t y  tx  x   x  t x    =   +   x จะได้  y   y  t y    P = P +T
  • 6. Two-Dimensional Rotation We generate a rotation transformation of an object by specifying a rotation axis and a rotation angle. A two-dimensional rotation of an object is obtained by repositioning the object along a circular path in the xy plane. Parameters for the two-dimensional rotation are  The rotation angle θ  A position (x,y) – rotation point (pivot point)
  • 7. The two-dimensional rotation x = r cos(φ + θ ) = r cos φ cos θ − r sin φ sin θ y = r sin(φ + θ ) = r cos φ sin θ + r sin φ cos θy Polar coordinate system x = r cos φ O ( x , y ) y = r sin φ O ( x, y ) θ φ x P(0,0) x = x cos θ − y sin θ y = x sin θ + y cos θ
  • 8. The two-dimensional rotation  x  cos θ - sinθ   x    = y y     sin θ cosθ   y    O ( x , y ) O = R • O O ( x, y ) θ โดยที่ φ x   x  x O=  O =   P(0,0)  y y    cos θ - sinθ  และ R =   Rotation matrix sin θ cosθ 
  • 9. Ex. 11.0 0.5
  • 10. Rotation of a point about an arbitrary pivot position x = ( x − xr ) cos θ − ( y − yr ) sin θ + xr y = ( x − xr ) sin θ + ( y − yr ) cos θ + yry O ( x , y )  x  cos θ - sinθ   x − xr   xr    =   y − y  +  y  O ( x, y )  y  sin θ cosθ     r  r θ O = R • O* + P φ P ( xr , y r ) x โดยที่ x − x  O* =   y − y   
  • 11. Two-Dimensional Scaling To alter the size of an object, we apply a scaling transformation. A simple two- x = x ⋅ sx dimensional scaling operation is performed by multiplying object y = y ⋅ sy positions (x,y) by scaling factors sx and sy to produce the  x  sx 0   x  transformed   =    coordinates (x’,y’).  y  0 s y   y    P = S•P
  • 12.  Any positive values can be assigned to the scaling factors.  Values less than 1 reduce the size of object;  Values greater than 1 produce enlargements.  Uniform scaling – scaling values have the same value  Differential scaling – unequal of the scaling factor
  • 13. Scaling relative to a chosen fixed point x = x ⋅ s x + x f (1 − s x ) y = y ⋅ s y + y f (1 − s y ) y P1  x   s x 0   x  1 − s x 0   x f  •   =     +  0 1-s   Pf ( x f , y f ) P2  y  0 s y   y     y  y f    P3 P = S • P + S * • Pf x
  • 14. 5.2 Matrix Representations and Homogeneous Coordinates Many graphics applications involve sequences of geometric transformations. Hence we consider how the matrix representations can be reformulated so that such transformation sequence can be efficiently processed. Each of three basic two-dimensional transformations (translation, rotation and scaling) can be expressed in the general matrix form
  • 15. P and P ’ = column vectors, coordinate positionM1 = 2 by 2 array containing P = M1 ⋅ P + M 2 multiplicative factors, for translation M1 is the identity matrixM2 = two-element column matrix containing translational terms, for rotation or scaling M2 contains the translational terms associated with the pivot point or scaling fixed point
  • 16. P = M1 ⋅ P + M 2  x  1 0  x  t x    =    y  + t  Translation  y  0 1    y    x  cos θ - sinθ   x − xr   xr   =   y − y  +  y  Rotation y  sin θ cosθ    r  r x  cos θ - sinθ   x  cos θ - sinθ   xr   xr   =    y  − sin θ cosθ   y  +  y  y  sin θ cosθ       r   r   x   s x 0   x  1 − s x 0   x f    =     +  0 1-s    Scaling  y  0 s y   y     y  y f   
  • 17.  To produce a sequence of transformations such as scaling followed by rotation then translation, we could calculate the transformed coordinates one step at a time. A more efficient approach is to combine the transformations so that the final coordinate positions are obtained directly from the initial coordinates, without calculating intermediate coordinate values.
  • 18. Homogeneous Coordinates Multiplicative and translational terms for a two-dimensional geometric transformations can be combined into a single matrix if we expand the representations to 3 by 3 matrices. Then we can use the third column of a transformation matrix for the translation terms, and all transformation equations can be expressed as matrix multiplications.
  • 19.  But to do so, we also need to expand the matrix representation for a two-dimensional coordinate position to a three-element column matrix. A standard technique for accomplishing this is to expand each two-dimensional coordinate-position representation (x,y) to a three-element representation (xh,yh,h), called homogeneous coordinates, where the homogeneous parameter h is a nonzero value such that xh yh x= , y= h h
  • 20.  A convenient choice is simply to set h=1. Each two-dimensional position is then represented with homogeneous coordinate (x,y,1). The term “homogeneous coordinates” is used in mathematics to refer to the effect of this representation on Cartesian equations.
  • 21. x   1 0 t x x        y  = 0 1 t y  y  Translation   0 1 0 1  1      P = T (t x , t y ) ⋅ P  x  cos θ - sinθ 0   x     Rotation  y  = sin θ cosθ 0  y    1   0 0 1  1       x  sx 0 0   x  P = R (θ ) ⋅ P     y  = 0 s y 0   y  Scaling1  0 0 1 1     P = S (sx , s y ) ⋅ P
  • 22. 5.3 Inverse Transformations 1 0 - t x  Inverse translation matrix −1   T = 0 1 - t y  0 0 1    Inverse rotation matrix 1  s 0 0  cos θ sinθ 0  x R −1 = − sin θ cosθ 0 −1  1    S = 0 0  0  0 1 sy   0 0 1 Inverse scaling matrix    
  • 23. 5.4 Two-Dimensional Composite Transformations Using matrix representations, we can set up a sequence of transformations as a composite transformation matrix by calculating the product of the individual transformations. Thus, if we ant to apply two transformations to point position P, the transformed location would be calculated as P = M 2 ⋅ M1 ⋅ P P = M ⋅P
  • 24. (1,3) (2,3) (3,2) (-2,1) (-1,1) (1,1) (2,1) (a) (b) (-2,-1) (-1,-1) (1.63,2.37) (0.77,1.87) (-1.37,0.37) (2.63,0.63)(-2.23,-0.13) (1.77,0.13) (c) (d) (-0.37,-1.37) (-1.23,-1.87)
  • 25. Composite Two-dimensional Translations P = T (t 2 x , t 2 y ) ⋅ {T (t1x , t1 y ) ⋅ P} P = {T (t 2 x , t 2 y ) ⋅ T (t1x , t1 y )} ⋅ P composite transformation matrix 1 0 t 2 x   1 0 t1x    1 0 t1x + t 2 x          0 1 t 2 y  ⋅  0 1 t1 y   =  0 1 t1 y + t 2 y    0 0 1   0 0 1    0 0 1         T (t 2 x , t 2 y ) ⋅ T (t1x , t1 y ) = T (t1x + t 2 x , t1 y + t 2 y )
  • 26. Composite Two-dimensional Rotations P = R (θ 2 ) ⋅ {R (θ1 ) ⋅ P} P = {R (θ 2 ) ⋅ R (θ1 )} ⋅ P composite transformation matrix R (θ 2 ) ⋅ R (θ1 ) = R (θ1 + θ 2 )
  • 27. Composite Two-dimensional Scaling composite transformation matrix S 2 x 0 0   S1x 0 0   S1x ⋅ S 2 x 0 0     0 S 2 y 0 ⋅ 0 S1 y 0  =  0 S1 y ⋅ S 2 y 00 0 1 0 0 1  0 0 1     S ( s2 x , s2 y ) ⋅ S ( s1x , s1 y ) = S ( s1x ⋅ s2 x , s1 y ⋅ s2 y )
  • 28. General Two-dimensional Pivot- Point Rotation A transformation sequence for rotating an object about a sepcified pivot point using the rotation matrix R(θ).  Translate the object so that the pivot-point position is moved to the coordinate origin.  Rotate the object about the coordinate origin.  Translate the object so that the pivot point is returned to its original position.
  • 29. (xr,yr) (xr,yr)(a) (b) (xr,yr) (xr,yr)(c) (d)
  • 30. 1 0 xr  cos θ - sinθ 0  1 0 - xr 0 1 y  ⋅ sin θ cosθ 0 ⋅ 0 1 - y  r    r0 0 1   0   0 1  0 0 1     cos θ - sinθ xr( 1- cos θ) + yr sin θ  = sin θ cosθ y ( 1- cos θ) − x sin θ  r r   0  0 1  T ( xr , yr ) ⋅ R (θ ) ⋅ T (− xr ,− yr ) = R ( xr , yr , θ )
  • 31. General Two-dimensional Fixed- Point Scaling A transformation sequence to produce a two- dimensional scaling with respect to a selected fixed position (xf,yf).  Translate the object so that the fixed point coincides with the coordinate origin.  Scale the object with respect to the coordinate origin.  Use the inverse of the translation in step (1) to return the object to its original position.
  • 32. (xf,yf) (xf,yf)(a) (b) (xf,yf) (xf,yf)(c) (d)
  • 33. 1 0 x f   s x 0 0  1 0 - x f      0 1 y f  ⋅  0 s y 0  ⋅ 0 1 - y f 0 0 1   0 0 1  0 0 1        s x 0 x f ( 1-s x )   = 1 s y y f ( 1-s y ) 0 0 1   T ( x f , y f ) ⋅ S ( s x , s y ) ⋅ T (− x f ,− y f ) = S ( x f , y f , ( s x , s y ))
  • 34. General Two-dimensional Scaling Directions We can scale an object in other directions by rotating the object to align the y desired scaling directions s2 with the coordinate axes before applying the scaling transformation. Suppose we want to apply scaling factors with values specified by parameters s1 x and s2 in the directions s1 shown in fig.
  • 35. The composite matrix resulting from the product of - rotation so that the directions for s1 and s2 coincide with the x and y axes - scaling transformation S(s1,s2) - opposite rotation to return points to their original orientations  s1Cos 2θ + s2 Sin 2θ ( s2 − s1 )CosθSinθ 0  R (θ ) ⋅ S ( s1 , s2 ) ⋅ R (θ ) = ( s2 − s1 )CosθSinθ s1Sin 2θ + s2Cos 2θ -1 0  0 0 1  
  • 36. y y (2,2) (1/2,3/2)(0,1) (1,1) (3/2,1/2)(0,0) (1,0) x (0,0) x s1= 1 s2=2
  • 37. Matrix Concatenation Properties Transformation products may not be commutative. The matrix product M2M1 is not equal to M1M2. This means that if we want to translate and rotate an object, we must be careful about the order in which the composite matrix is evaluated. Reversing the order in which a sequence of transformations is performed may affect the transformed position of an object.
  • 38. 2 Rotation1 Translation1 Rotation 2 Translation
  • 39. General Two-dimensional Composite Transformations and Computational Efficiency  x  rs xx rs xy trs x   x        y  = rs yx rs yy trs y   y  1   0 0 1  1       rs** are the multiplicative rotation-scaling terms (rotation angles, scaling factors) trsx and trsy are the translation terms (translation distances, pivot-point and fixed- point coordinates, rotation angles, scaling parameters)
  • 40. Example  Scale and  rotate about its centroid coordinates (xc,yc) and  translateT (t x , t y ) ⋅ R ( xc , yc , θ ) ⋅ S ( xc , yc , s x , s y ) =  s x cos θ - s y sin θ xc (1 − s x cos θ ) + yc s y sin θ + t x     s x sin θ s y cos θ yc (1 − s y cos θ ) − xc s x sin θ + t y   0 0 1   
  • 41. Two-dimensional Rigid-body Transformation If a transformation matrix includes only translation and rotation parameters, it is a rigid-body transformation matrix. rxx rxy trx    ryx ryy try  0 0 1    r** are the multiplicative rotation terms (rotation angles) trx and try are the translation terms (translation distances, pivot-point and fixed-point coordinates, rotation angles)
  • 42. 5.5 Other Two-Dimensional TransformationsReflection For a two-dimensional reflection, the image is generated relative to an axis of reflection by rotating the object 180º about the reflection axis.
  • 43. Reflection about the line y=0 (the x axis) 1 0 0 0 - 1 0    0 0 1   
  • 44. Reflection about the line x=0 (the y axis)  − 1 0 0  0 1 0    0 0 1  
  • 45. Reflection about any reflection point in the xy plane Reflection point − 1 0 0   0 - 1 0    0 0 1   
  • 46. Reflection about the reflection axis y=x 0 1 0  1 0 0   0 0 1   1. Rotate the line y=x with respect to the original through a 45 angle2. Reflection with respect to the x axis3. Rotate the line y=x black to its original position with a counterclockwise rotation through 45
  • 47. Reflection about the reflection axis y=-x  0 - 1 0 - 1 0 0     0 0 1  1. Clockwise rotate the line y=-x with respect to the original through a 45 angle2. Reflection with respect to the y axis3. Rotate the line y=-x black to its original position with a y = -x counterclockwise rotation through 45
  • 48. Shear A transformation that distorts the shape of an object such that the transformed shape appears as if the object were composed of internal layers that had been caused to slide over each other is called a shear.
  • 49.  An x-direction shear 1 shx 0 0 1 0  transformation matrix   0 0 1   y y (2,1) (3,1)(0,1) (1,1) shx = 2(0,0) (1,0) (0,0) (1,0)
  • 50.  We can generate x-direction shears relative to other reference lines 1 shx -shx ⋅ yref    0 1 0  transformation matrix 0 0 1    y y (1,1) (2,1)(0,1) (1,1) shx = ½ yref = -1(0,0) (1,0) (0,0) (1/2,0) (3/2,0) yref = -1 yref = -1
  • 51.  A y-direction shears relative to the line x=xref is generated with 1 0 0     shy 1 -shy ⋅ xref  transformation matrix 0 0 1    y y (1,2) (0,3/2) (0,1) (1,1) (1,1) shy = ½ (0,1/2) xref = -1xref = -1 (0,0) (1,0) xref = -1 (0,0)
  • 52.  Shear operations can be expressed as sequences of basic transformations. The x-direction shear matrix 1 shx 0 0 1 0    0 0 1   can be represented as a composite transformation involving a series of rotation and scaling metrices.
  • 53. 5.6 Raster Methods for Geometric Transformations Functions that manipulate rectangular pixel arrays are called raster operations and moving a block of pixel values from one position to another is termed a block transfer, a bitblt or a pixblt. All bit settings in the rectangular area are copied as a block into another part of the frame buffer. We can erase the pattern at the original location by assigning the background color to all pixels within that block.
  • 54. Array rotations that are not multiples of 90º 1 2 3 12 11 10  4 3 6 9 12  5 6  2 5 8 11 9  8 7  7 8 9   6 5 4   1 4 7 10      10 11 12 3 2 1 (a) (b) (c)The original array is shown in (a),the positions of the array elements after a 90ºcounterclockwise rotation are shown in (b), andthe position of the array elements after a 180ºrotation are shown in (c).
  • 55. 5.7 OpenGL Raster Transformations A translation of a rectangular array of pixel- color values from one buffer area to another can be accomplished in OpenGL as a copy operation:glCopyPixels(xmin, ymin, width, height, GL_COLOR); This array of pixels is to be copied to a rectangular area of a refresh buffer whose lower-left corner is at the location specified by the current raster position.
  • 56.  We can rotate a block of pixel-color values in 90-degree increments by  first saving the block in an array,glReadPixels(xmin, ymin, width, height, GL_RGB, GL_UNSIGNED_BYTE, colorArray);  then rearranging the elements of the array and  placing it back in the refresh buffer.glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, colorArray); We set the scaling facters withglPixelZoom(sx,sy);
  • 57. 5.8 Transformations between Two- Dimensional Coordinate Systems y’ y x’ θ yn xn xA Cartesian x’y’ system specified with coordinate origin(xn,yn) and orientation angle θ in a Cartesian xy referenceframe.
  • 58.  To transform object descriptions from xy coordinates to x’y’ coordinates, we set up a transformation that superimposes the axes onto the x’y’ axes. This is done in two steps:  Translate so that the origin (xn,yn) of the x’y’ system is moved to the origin (0,0) of the xy system.  Rotation the x’ axis onto the x axis.
  • 59. 1 0 − xn  1)Translation 0 1 − y  T ( − xn , − y n ) =  n 0 0 1    y’y y P y ’ x’ P y x’ y’ θyn x’ θ xn x x x
  • 60. 2)clockwise rotation  cosθ sinθ 0 2.1) R(−θ ) = - sinθ cosθ 0     0  0 1 y yy ’ y ’ P P y y x’ y’ x’ θ x x x x composite matrix M xy , x y = R (−θ ) ⋅ T (− xn ,− yn )
  • 61. OR  2.2) An alternate method for describing the orientation of the x’y’ coordinate system is to specify a vector V that indicates the direction for the positive y’ axis.  We can specify vector V as a point in the xy reference frame relative to the origin of the xy system, which we can convert to y’ the unit vector, yV P V x’ v= = (v x , v y ) V yn θ xn x
  • 62.  We obtain the unit vector u along the x’ axis by applying a 90º clockwise rotation to vector v u = (v y ,−v x ) = (u x , u y ) The matrix to rotate the x’y’ system into coincidence with the xy system can be written as u x u y 0    R = v x v y 0  0 0 1  
  • 63. OR  In the case that we coordinates of P0 and P1 are known, P1 - P0 v= = (v x , v y ) P1 - P0 y’ yV P x’ P1 yn θ P0 xn x
  • 64. (xf,yf) (xf,yf) (a) (b) (xf,yf) (xf,yf) (xf,yf)(c) (d) (e)
  • 65. (xf,yf)(xf,yf)(f)