2D Transformations.

Slides:



Advertisements
Similar presentations
Computer Graphics: 3D Transformations
Advertisements

Computer Graphics - Transformation -
Computer Graphics 2D & 3D Transformation.
COMPUTER GRAPHICS 2D TRANSFORMATIONS.
Gursharan Singh Tatla TRANSFORMATIONS Gursharan Singh Tatla Gursharan Singh Tatla.
CLASS 4 CS770/870. Translation Scale Multiplying Matrices. The R C rule What happens when we do two translates? What happens when we do two scales?
University of North Carolina at Greensboro
1 Computer Graphics Chapter 6 2D Transformations.
Two-Dimensional Geometric Transformations
2D TRANSFORMATIONS.
CMPE 466 COMPUTER GRAPHICS
Linear Algebra and SVD (Some slides adapted from Octavia Camps)
CS 4731: Computer Graphics Lecture 7: Introduction to Transforms, 2D transforms Emmanuel Agu.
Objectives Learn to build arbitrary transformation matrices from simple transformations Learn to build arbitrary transformation matrices from simple transformations.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 OpenGL Transformations Ed Angel Professor of Computer Science, Electrical and Computer.
2IV60 Computer Graphics 2D transformations
2D Transformations x y x y x y. 2D Transformation Given a 2D object, transformation is to change the object’s Position (translation) Size (scaling) Orientation.
2D Transformations Unit - 3. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale it.
2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together.
3D Transformation. In 3D, we have x, y, and z. We will continue use column vectors:. Homogenous systems:. 3D Transformation glVertex3f(x, y,z);
TWO DIMENSIONAL GEOMETRIC TRANSFORMATIONS CA 302 Computer Graphics and Visual Programming Aydın Öztürk
Graphics Graphics Korea University kucg.korea.ac.kr Transformations 고려대학교 컴퓨터 그래픽스 연구실.
Geometric Transformations Jehee Lee Seoul National University.
 2D Transformations 2D Transformations  Translation Translation  Rotation Rotation  Scaling Scaling.
Geometric Transformations
Geometry: 2-D Transformations Course web page: Chapter #3.
Computer Graphics 2D Transformations. 2 of 74 Contents In today’s lecture we’ll cover the following: –Why transformations –Transformations Translation.
1 Computer Graphics Week9 -3D Geometric Transformation.
Computer Graphics I, Fall 2010 OpenGL Transformations.
3D Transformations. Translation x’ = x + tx y’ = y + ty z’ = z + tz P = P’ = T = P’ = T. P tx ty tz xyz1xyz1 x’ y’ z’ 1 x y.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 OpenGL Transformations.
Two-Dimensional Geometric Transformations A two dimensional transformation is any operation on a point in space (x, y) that maps that point's coordinates.
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
2D Geometric Transformation Translation A translation is applied to an object by repositioning it along a straight-line path from one coordinate location.
Geometric Transformations Sang Il Park Sejong University Many slides come from Jehee Lee’s.
CS552: Computer Graphics Lecture 4: 2D Graphics. Recap 2D Graphics Coordinate systems 2D Transformations o Translation o Scaling o Rotation Combining.
Composing Transformations
Learning Objectives Affine transformations Affine transformations Translation Translation Rotation Rotation Scaling Scaling Reflection Reflection Shear.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 73 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 73 Computer Graphics Three-Dimensional Graphics II.
1 OpenGL Transformations. 2 Objectives Learn how to carry out transformations in OpenGL ­Rotation ­Translation ­Scaling Introduce OpenGL matrix modes.
1 By Dr. HANY ELSALAMONY.  We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations.
Homogeneous Coordinates and Matrix Representations Cartesian coordinate (x, y, z) Homogeneous coordinate (x h, y h, z h, h) Usually h = 1. But there are.
1 Geometric Transformations-II Modelling Transforms By Dr.Ureerat Suksawatchon.
Geometric Transformations. Transformations Linear transformations Rigid transformations Affine transformations Projective transformations T Global reference.
Jinxiang Chai CSCE441: Computer Graphics 3D Transformations 0.
1 Geometric Transformations Modelling Transforms By Dr.Ureerat Suksawatchon.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
Computer Graphic 2 D Transformation.
CSCE 441 Computer Graphics: 2D Transformations
Transformations. Transformations Introduce standard transformations ◦ Rotation ◦ Translation ◦ Scaling ◦ Shear Derive homogeneous coordinate transformation.
학기 Chapter 5. Geometric Transformations 1.
Forward Projection Pipeline and Transformations CENG 477 Introduction to Computer Graphics.
OpenGL Transformations
2D Geometric Transformations
Summary of Properties of 3D Affine Transformations
Computer Graphics OpenGL Transformations
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Geometric Transformations
Unit-5 Geometric Objects and Transformations-II
Chapter 4/5 glMatrixMode Modeling Transformations glTranslate glScale
Computer Graphics Lecture 12 2D Transformations II Taqdees A
Geometric Transformations for Computer Graphics
Geometric Transformations
The Modelview Matrix Lecture 8 Mon, Sep 10, 2007.
Three-Dimensional Graphics
Transformations in OpenGL
Geometric Objects and Transformations (II)
Geometric Transformations
TWO DIMENSIONAL TRANSFORMATION
Lecture #6 2D Geometric Transformations
Presentation transcript:

2D Transformations

Translation tx ty x y x’ y’ 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 (x’,y’) r q (x,y) F x cos q -sin q sin q cos q

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

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

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

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

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

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

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

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

Inverse Transformations 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

Composite Transformations P’ = M3 . 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 )

Pivot-point Rotation y (xr, yr) x

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

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

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

Fixed-point Scaling y (xf, yf) x

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

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

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

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

Rigid-Body Transformation

Reflection y 1 0 0 0 -1 0 0 0 1 x

Reflection y -1 0 0 0 1 0 0 0 1 x

Reflection y -1 0 0 0 -1 0 0 0 1 x

Reflection y 0 1 0 1 0 0 0 0 1 x

Shear y 1 shx 0 0 1 0 0 0 1 x y x

Raster Methods Translation Block transfer of the refresh buffer area

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

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.

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.

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

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

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

OpenGL glTranslate* (tx, ty, tz) glRotate* (theta, vx, vy, vz) 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)

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

OpenGL glMatrixMode(GL_MODELVIEW) glLoadIdentity ( ) 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’

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

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); /* T(125,125).R(90).T(-125,-125).P */

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); /* T(125,125).R(90).T(-125,-125).P */

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); /* T(125,125).R(90).T(-125,-125).P */

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);

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); glLoadIdentity ( ); glRotatef(90.0, 0.0, 0.0, 1.0);

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); glLoadIdentity ( ); glRotatef(90.0, 0.0, 0.0, 1.0); glScalef(-0.5, 1.0, 1.0);

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); glPopMatrix(); glRotatef(90.0, 0.0, 0.0, 1.0); glScalef(-0.5, 1.0, 1.0);