CS552: Computer Graphics Lecture 4: 2D Graphics. Recap 2D Graphics Coordinate systems 2D Transformations o Translation o Scaling o Rotation Combining.

Slides:



Advertisements
Similar presentations
Today Composing transformations 3D Transformations
Advertisements

Computer Graphics 2D & 3D Transformation.
COMPUTER GRAPHICS 2D TRANSFORMATIONS.
Computer Graphics Lecture 4 Geometry & Transformations.
University of North Carolina at Greensboro
Geometric Transformations
1 Computer Graphics Chapter 6 2D Transformations.
Chapter 5 Geometric Transformations
2D TRANSFORMATIONS. 2D Transformations What is transformations? –The geometrical changes of an object from a current state to modified state. Why the.
25 May May May 2015Week 5-2D Transformations1 2D Transformations By: KanwarjeetSingh.
2D TRANSFORMATIONS.
CMPE 466 COMPUTER GRAPHICS
2D Geometric Transformations
CS 4731: Computer Graphics Lecture 7: Introduction to Transforms, 2D transforms Emmanuel Agu.
1 CSCE 441 Computer Graphics: 2D Transformations Jinxiang Chai.
2.1 si SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling.
Computer Graphics CSC 630 Lecture 2- Linear Algebra.
Computer Graphics with OpenGL 3e
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.
CAP4730: Computational Structures in Computer Graphics
2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together.
CS 450: Computer Graphics 2D TRANSFORMATIONS
Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations.
Transformations Dr. Amy Zhang.
TWO DIMENSIONAL GEOMETRIC TRANSFORMATIONS CA 302 Computer Graphics and Visual Programming Aydın Öztürk
Graphics Graphics Korea University kucg.korea.ac.kr Transformations 고려대학교 컴퓨터 그래픽스 연구실.
2D Transformation of Graphics
2D Transformations.
Geometric Transformations Jehee Lee Seoul National University.
GRAFIKA KOMPUTER ~ M. Ali Fauzi. Drawing 2 D Graphics.
Transformations Jehee Lee Seoul National University.
Geometric Transformations
Computer Graphics 2D Transformations. 2 of 74 Contents In today’s lecture we’ll cover the following: –Why transformations –Transformations Translation.
2D Transformation. Transformation changes an object’s: – Position(Translation) – Size(Scaling) – Orientation(Rotation) – Shape(Deformation) Transformation.
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.
Affine Transformation. Affine Transformations In this lecture, we will continue with the discussion of the remaining affine transformations and composite.
Geometric Transformations Sang Il Park Sejong University Many slides come from Jehee Lee’s.
Lecture 5: Introduction to 3D
Foundations of Computer Graphics (Spring 2012) CS 184, Lecture 3: Transformations 1
CS552: Computer Graphics Lecture 6: Viewing in 2D.
Composing Transformations
Learning Objectives Affine transformations Affine transformations Translation Translation Rotation Rotation Scaling Scaling Reflection Reflection Shear.
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 Teaching Innovation - Entrepreneurial - Global The Centre for Technology enabled Teaching & Learning, N Y S S, India DTEL DTEL (Department for Technology.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
2D Transformations What is transformations? The geometrical changes of an object from a current state to modified state. Why the transformations is needed?
CSCE 441 Computer Graphics: 2D Transformations
Transformations. Transformations Introduce standard transformations ◦ Rotation ◦ Translation ◦ Scaling ◦ Shear Derive homogeneous coordinate transformation.
Modeling Transformation
학기 Chapter 5. Geometric Transformations 1.
Forward Projection Pipeline and Transformations CENG 477 Introduction to Computer Graphics.
Geometric Transformations
2D TRANSFORMATIONS.
2D Transformations By: KanwarjeetSingh
2D Geometric Transformations
2D Imaging and Transformation
Review: Transformations
Introduction to Computer Graphics CS 445 / 645
Review: Transformations
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Transformations.
Three-Dimensional Graphics
Geometric Objects and Transformations (II)
TWO DIMENSIONAL TRANSFORMATION
Lecture #6 2D Geometric Transformations
Presentation transcript:

CS552: Computer Graphics Lecture 4: 2D Graphics

Recap 2D Graphics Coordinate systems 2D Transformations o Translation o Scaling o Rotation Combining Transformations

Objective After completing this lecture students will be able to o Perform composite transformations in 2D o Solve mathematical problems on generalized 2D transform o Transform object coordinate to Cartesian coordinate o Write program in OpenGL to perform 2D transform

Combining transformations We have a general transformation of a point: P' = M P + A When we scale or rotate, we set M, and A is the additive identity. When we translate, we set A, and M is the multiplicative identity. To combine multiple transformations, we must explicitly compute each transformed point. Is it possible to use the same matrix operation all the time? How to combine multiplication and addition into a single operation?

Homogeneous coordinates Uniform representation of translation, rotation, scaling Uniform representation of points and vectors Compact representation of sequence of transformations

Homogeneous coordinate Add extra coordinate: P = (p x, p y, p h ) or x = (x, y, h) Cartesian coordinates: divide by h x = (x/h, y/h) Points: h = 1 (for the time being…), vectors: h = 0 yy x x w 

We can always map back to the original 2D point by dividing by the last coordinate (15, 6, 3) ---  (5, 2). (60, 40, 10) -  ?. Why do we use 1 for the last coordinate? The fact that all the points along each line can be mapped back to the same point in 2D gives this coordinate system its name – homogeneous coordinates. Homogeneous coordinate

Matrix Representation Point in column-vector: A point now has three coordinates. So the matrix is needs to be 3x3. Translation xy1xy1

Rotation Scaling Matrix Representation

Composite Transformation We can represent any sequence of transformations as a single matrix. o No special cases when transforming a point – matrix vector. o Composite transformations – matrix matrix. Composite transformations: o Rotate about an arbitrary point – translate, rotate, translate o Scale about an arbitrary point – translate, scale, translate o Change coordinate systems – translate, rotate, scale Does the order of operations matter?

Composition Properties Is matrix multiplication associative? o (A.B).C = A.(B.C)                          dhlcfldgjcejdhkcfkdgicei bhlaflbgjaejbhkafkbgiaei lk ji dhcfdgce bhafbgae                             lk ji hg fe dc ba                          dhldgjcflcejdhkdgicfkcei bhlbgjaflaejbhkbgiafkaei hlgjhkgi flejfkei dc ba                             lk ji hg fe dc ba ?

Is matrix multiplication commutative? o A. B = B. A Composition Properties ?

Order of operations So, it does matter. Let’s look at an example: 1.Translate 2.Rotate 1.Rotate 2.Translate

Composite Transformation Matrix Arrange the transformation matrices in order from right to left. General Pivot- Point Rotation Operation :- 1.Translate (pivot point is moved to origin) 2.Rotate about origin 3.Translate (pivot point is returned to original position) T(pivot) R(  ) T(–pivot) 1 0 -t x 0 1 -t y cos  -sin  0 sin  cos  t x 0 1 t y cos  -sin  -t x cos  + t y sin  + t x sin  cos  -t x sin  - t y cos  + t y cos  -sin  -t x cos  + t y sin  sin  cos  -t x sin  - t y cos  t x 0 1 t y

Composite Transformation Matrix General Fixed-Point Scaling Operation :- 1.Translate (fixed point is moved to origin) 2.Scale with respect to origin 3.Translate (fixed point is returned to original position) T(fixed) S(scale) T(–fixed) Find the matrix that represents scaling of an object with respect to any fixed point? Given P(6, 8), Sx = 2, Sy = 3 and fixed point (2, 2). Use that matrix to find P’?

Composite Transformation Matrix General Scaling Direction Operation :- 1. Rotate (scaling direction align with the coordinate axes) 2. Scale with respect to origin 3. Rotate (scaling direction is returned to original position) R(–  ) S(scale) R(  ) Find the composite transformation matrix (Homework)

Computational efficiency A two-dimensional transformation can be represented as:

Computational efficiency Example: In practice: E.g. Rotation Can we approximate??

2D- Rigid body transformation If the transformation involves only rotation and translation, i.e. Angles and distances between coordinate positions are unchanged Orthonormal matrix How to use this property?

Constructing 2D Rotation Matrices Constructing the matrix when we know the final orientation of an object Rather than the amount of angular rotation necessary to put the object into that position

Reflection about a line

Shear A transformation that distorts the shape of an object An x-direction shear relative to the x axis

Shear w.r.to a reference x-direction shears relative to other reference lines Composite matrix:

2D Coordinate Transformation Converting from one 2D Cartesian frame to the other

2D Coordinate Transformation (1)

2D Coordinate Transformation (2)

2D Coordinate Transformation: Alternative Is the idea of unit vector going to help?

How to do it in OpenGL? Translate class wcPt2D { // A point class public: GLfloat x, y; }; void translatePolygon (wcPt2D * verts, GLint nVerts, GLfloat tx, GLfloat ty) { GLint k; for (k = 0; k < nVerts; k++) { verts [k].x = verts [k].x + tx; verts [k].y = verts [k].y + ty; } glBegin (GL_POLYGON); for (k = 0; k < nVerts; k++) glVertex2f (verts [k].x, verts [k].y); glEnd ( ); }

How to do it in OpenGL? Rotate void rotatePolygon (wcPt2D * verts, GLint nVerts, wcPt2D pivPt, GLdouble theta) { wcPt2D * vertsRot; GLint k; for (k = 0; k < nVerts; k++) { vertsRot [k].x = pivPt.x + (verts [k].x - pivPt.x) * cos (theta) - (verts [k].y - pivPt.y) * sin (theta); vertsRot [k].y = pivPt.y + (verts [k].x - pivPt.x) * sin (theta) + (verts [k].y - pivPt.y) * cos (theta); } glBegin {GL_POLYGON}; for (k = 0; k < nVerts; k++) glVertex2f (vertsRot [k].x, vertsRot [k].y); glEnd ( ); }

Scaling using OpenGL void scalePolygon (wcPt2D * verts, GLint nVerts, wcPt2D fixedPt, GLfloat sx, GLfloat sy) { wcPt2D vertsNew; GLint k; for (k = 0; k < nVerts; k++) { vertsNew [k].x = verts [k].x * sx + fixedPt.x * (1 - sx); vertsNew [k].y = verts [k].y * sy + fixedPt.y * (1 - sy); } glBegin {GL_POLYGON}; for (k = 0; k < nVerts; k++) glVertex2f (vertsNew [k].x, vertsNew [k].y); glEnd ( ); }

OpenGL 2D transformations 1 Internally: Coordinates are four-element row vectors Transformations are 4  4 matrices 2D trafo’s: Ignore z-coordinates, set z = 0.

OpenGL 2D transformations 2 OpenGL maintains two matrices: GL_PROJECTION GL_MODELVIEW Transformations are applied to the current matrix, to be selected with: glMatrixMode(GL_PROJECTION) or glMatrixMode(GL_MODELVIEW)

OpenGL 2D transformations 3 Initializing the matrix to I: glLoadIdentity(); Replace the matrix with M: GLfloat M[16]; fill(M); glLoadMatrix*(M); Matrices are specified in column-major order: Multiply current matrix with M: glMultMatrix*(M);

OpenGL 2D transformations 4 Basic transformation functions: generate matrix and post-multiply this with current matrix. Translate over [tx, ty, tz]: glTranslate*(tx, ty, tz); Rotate over theta degrees (!) around axis [vx, vy, vz]: glRotate*(theta, vx, vy, vz); Scale axes with factors sx, sy, sz: glScale*(sx, sy, sz);

OpenGL 2D Transformations 5 OpenGL maintains stacks of transformation matrices. Two operations: glPushMatrix(): Make copy of current matrix and put that on top of the stack; glPopMatrix(): Remove top element of the stack. Handy for dealing with hierarchical models Handy for “undoing” transformations

OpenGL 2D Transformations 6 Standard: glRotate(10, 1, 2, 0); glScale(2, 1, 0.5); glTranslate(1, 2, 3); glutWireCube(1); glTranslate(  1,  2,  3); glScale(0.5, 1, 2); glRotate(  10, 1, 2, 0); Using the stack: glPushMatrix(); glRotate(10, 1, 2, 0); glScale(2, 1, 0.5); glTranslate(1, 2, 3); glutWireCube(1); glPopMatrix(); Undo transformation Shorter, more robust

Summary of important functions

Thank you Next Lecture: Introduction to 3D Graphics