1 / 44

2D Transformations

2D Transformations. Translation. x’ = x + tx y’ = y + ty translation vector: T = P = P’ = P’ = P + T. y. tx ty. (x’,y’). (x,y). x. x y. x’ y’. Rotation. Rotation about the origin x’ = r.cos( F + q ) y’ = r.sin( F + q ) Rotation matrix: R = P’ = R . P. y.

jolene
Télécharger la présentation

2D Transformations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 2D Transformations

  2. Translation x’ = x + tx y’ = y + ty translation vector: T = P = P’ = P’ = P + T y tx ty (x’,y’) (x,y) x x y x’ y’

  3. Rotation Rotation about the origin x’ = r.cos(F+q ) y’ = r.sin(F+q ) Rotation matrix: R = P’ = R . P y (x’,y’) r q (x,y) F x cos q -sin q sin q cos q

  4. Rotation Rotation about an arbitrary point (xr, yr) x’ = xr + (x-xr).cos q - (y-yr).sin q y’ = yr + (x-xr).sin q - (y-yr).cos q y (x’,y’) q (x,y) F (xr,yr) x

  5. Scaling x’ = x . sx y’ = y . sy Scaling matrix : S = P’ = S . P y sx 0 0 sy x

  6. Scaling Fixed point scaling x’ = x . sx + xf (1-sx) y’ = y . sy + yf (1-sy) y (xf,yf) x

  7. Homogeneous Coordinates (x, y) (x, y, h) ah = 1  a = 1/h (ax, ay, ah) = (x/h, y/h, 1) h (x, y, h) (ax, ay, ah) (0,0,1) x y

  8. Homogeneous Coordinates (x,y) (xh, yh, h) xh= h.x yh= h.y (xh, yh, h) = (h.x, h.y, h)

  9. Translation x’ y’ 1 P = P’ = translation matrix:T(tx, ty) = P’ = T(tx, ty) . P x y 1 1 0 tx 0 1 ty 0 0 1

  10. Rotation Rotation matrix: R = P’ = R(q) . P cos q -sin q 0 sin q cos q 0 0 0 1

  11. Scaling Scaling matrix : S = P’ = S(sx, sy) . P sx 0 0 0 sy 0 0 0 1

  12. Inverse Transformations T-1 = R-1 = S-1 = 0 0 -tx 0 0 -ty 0 0 1 cos q sin q 0 -sin q cos q 0 0 0 1 1/sx 0 0 0 1/sy 0 0 0 1

  13. Composite Transformations P’ = M2 . M1 . P = M . P M: composite matrix T(t2x, t2y) . T(t1x, t1y) = T( t1x+t2x, t1y+t2y ) R(q2) . R(q1) = R( q1+q2 ) S(s2x, s2y) . S(s1x, s1y) = S( s1x.s2x, s1y.s2y )

  14. Pivot-point Rotation y (xr, yr) x

  15. Pivot-point Rotation 1. Translate the object so that pivot-point is moved to the origin T(-xr, -yr) . P y x

  16. Pivot-point Rotation 1. Translate the object so that pivot-point is moved to the origin T(-xr, -yr) . P 2. Rotate object about the origin R(q) . T(-xr, -yr) . P y x

  17. Pivot-point Rotation 1. Translate the object so that pivot-point is moved to the origin T(-xr, -yr) . P 2. Rotate object about the origin R(q) . T(-xr, -yr) . P 3. Translate the object so that pivot-point is returned to its original position T(xr, yr) . R(q) . T(-xr, -yr) . P = R(xr, yr, q) y x

  18. Fixed-point Scaling y (xf, yf) x

  19. Fixed-point Scaling 1. Translate the object so that fixed-point is moved to the origin T(-xf, -yf) . P y x

  20. Fixed-point Scaling 1. Translate the object so that fixed-point is moved to the origin T(-xf, -yf) . P 2. Scale the object with respect to the origin S(sx, sy) . T(-xf, -yf) . P y x

  21. Fixed-point Scaling 1. Translate the object so that fixed-point is moved to the origin T(-xf, -yf) . P 2. Scale the object with respect to the origin S(sx, sy) . T(-xf, -yf) . P 3. Use inverse translation in step (1) T(xf, yf) . S(sx, sy) . T(-xf, -yf) . P = S(xf, yf, sx, sy) y x

  22. Scaling Directions 1. Rotate 2. Scale 3. Rotate back R-1(q) . S(s1, s2) . R(q) y s2 q x s1

  23. Rigid-Body Transformation

  24. Reflection y 1 0 0 0 -1 0 0 0 1 x

  25. Reflection y -1 0 0 0 1 0 0 0 1 x

  26. Reflection y -1 0 0 0 -1 0 0 0 1 x

  27. Reflection y 0 1 0 1 0 0 0 0 1 x

  28. Shear y 1 shx 0 0 1 0 0 0 1 x y x

  29. Raster Methods Translation Block transfer of the refresh buffer area

  30. Raster Methods Rotation 900 counterclockwise: 1. reverse pixel values in each row 2. interchange rows and columns 1800: 1. reverse the order of elements in each row 2. reverse the order of rows

  31. Raster Methods Rotation Other cases: 1. calculate the amount of overlap with the rotated pixel areas 2. compute the color by averaging the colors of the overlapped source pixels, weighted by their percentage of area overlap.

  32. Raster Methods Scaling 1. scale pixel areas in the original block using sx, sy 2. assign color of the destination pixel according to the overlap area.

  33. Raster Methods Reftection 1. reverse row and column values 2. translate Shear Shift the position of array values along rows or columns

  34. Transformations between 2D Coordinate Systems M = R(-q) . T(-x0, -y0) y y y’ y’ x’ q y0 x x x’ x0

  35. Transformations between 2D Coordinate Systems v = (vx, vy) u = (vy, -vx) R = y y’ V x’ v ux uy 0 vx vy 0 0 0 1 u x

  36. OpenGL • glTranslate* (tx, ty, tz) • f (float) • d (double) • glRotate* (theta, vx, vy, vz) • theta: rotation angle in degrees • (vx, vy, vz) vector defines the orientation of the rotation axis that passes through the coordinate origin • glScale* (sx, sy, sz)

  37. OpenGL • glMatrixMode(GL_MODELVIEW) • sets up the matrix for transformations (4x4 modelview matrix) • glLoadIdentity ( ) • assigns identity matrix to the current matrix • glLoadMatrix*(16-element array) • assigns a 16-element array (in column major order) to the current matrix • glMultMatrix*(16-element array) • postmultiplies a 16-element array (M’) with the current matrix (M) : M <- M.M’

  38. OpenGL glMatrixMode(GL_MODELVIEW); glLoadIdentity ( ); glMultMatrixf(M2); glMultMatrixf(M1); /* M = M2 . M1 */

  39. OpenGL Matrix Stack • Top matrix on the stack is the “current matrix” • Initially stack contains identity matrix • Maximum stack depth is 32 • glGetIntegerv (GL_MAX_MODELVIEW_STACK_DEPTH, stackSize) • returns the number of positions available in the modelview stack • glGetIntegerv (GL_MODELVIEW_STACK_DEPTH, numMats) • returns the number of matrices currently in the stack • glPushMatrix() • copies the current matrix at the top of the stack • glPopMatrix() • destroys the matrix at the top of the stack

  40. OpenGL glMatrixMode(GL_MODELVIEW); glColor3f(0.0, 0.0, 1.0); Recti(50, 100, 200, 150); glColor3f(1.0, 0.0, 0.0); glTranslatef(125.0, 125.0, 0.0); glRotatef(90.0, 0.0, 0.0, 1.0); glTranslatef(-125.0, -125.0, 0.0); Recti(50, 100, 200, 150); /* T(125,125).R(90).T(-125,-125).P */

  41. OpenGL glMatrixMode(GL_MODELVIEW); glColor3f(0.0, 0.0, 1.0); Recti(50, 100, 200, 150); glColor3f(1.0, 0.0, 0.0); glTranslatef(125.0, 125.0, 0.0); glRotatef(90.0, 0.0, 0.0, 1.0); glTranslatef(-125.0, -125.0, 0.0); Recti(50, 100, 200, 150); /* T(125,125).R(90).T(-125,-125).P */

  42. OpenGL glMatrixMode(GL_MODELVIEW); glColor3f(0.0, 0.0, 1.0); Recti(50, 100, 200, 150); glColor3f(1.0, 0.0, 0.0); glTranslatef(125.0, 125.0, 0.0); glRotatef(90.0, 0.0, 0.0, 1.0); glTranslatef(-125.0, -125.0, 0.0); Recti(50, 100, 200, 150); /* T(125,125).R(90).T(-125,-125).P */

  43. OpenGL glMatrixMode(GL_MODELVIEW); glColor3f(0.0, 0.0, 1.0); Recti(50, 100, 200, 150); glColor3f(1.0, 0.0, 0.0); glTranslatef(-200.0, -50.0, 0.0); Recti(50, 100, 200, 150); glLoadIdentity ( ); glRotatef(90.0, 0.0, 0.0, 1.0); Recti(50, 100, 200, 150); glLoadIdentity ( ); glScalef(-0.5, 1.0, 1.0); Recti(50, 100, 200, 150);

  44. OpenGL glMatrixMode(GL_MODELVIEW); glColor3f(0.0, 0.0, 1.0); Recti(50, 100, 200, 150); glPushMatrix(); glColor3f(1.0, 0.0, 0.0); glTranslatef(-200.0, -50.0, 0.0); Recti(50, 100, 200, 150); glPopMatrix(); glPushMatrix(); glRotatef(90.0, 0.0, 0.0, 1.0); Recti(50, 100, 200, 150); glPopMatrix(); glScalef(-0.5, 1.0, 1.0); Recti(50, 100, 200, 150);

More Related