2IV60 Computer Graphics 2D transformations

Slides:



Advertisements
Similar presentations
Computer Graphics 2D & 3D Transformation.
Advertisements

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?
Computer Graphics Lecture 4 Geometry & Transformations.
University of North Carolina at Greensboro
Geometric Transformations
1 Computer Graphics Chapter 6 2D Transformations.
CMPE 466 COMPUTER GRAPHICS
CS 4731: Computer Graphics Lecture 7: Introduction to Transforms, 2D transforms Emmanuel Agu.
Graphics-1 Gentle Introduction to Computer Graphics (2) Based on: –David Brogan’s “Introduction to Computer Graphics” Course Slides, University of Virginia.
1 CSCE 441 Computer Graphics: 2D Transformations Jinxiang Chai.
2.1 si SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling.
Transformations Objectives Understand how transformations work in 2D and 3D Understand the concept of homogenous coordinate system Understand scene graphs.
Computer Graphics CSC 630 Lecture 2- Linear Algebra.
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.
2IV60 Computer graphics set 4:3D transformations and hierarchical modeling Jack van Wijk TU/e.
2IV60 Computer Graphics Basic Math for CG
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 Transformations.
Lecture Notes: Computer Graphics.
Geometric Transformations Jehee Lee Seoul National University.
Transformations Jehee Lee Seoul National University.
Geometry: 2-D Transformations Course web page: Chapter #3.
1 Computer Graphics Week9 -3D Geometric Transformation.
16/5/ :47 UML Computer Graphics Conceptual Model Application Model Application Program Graphics System Output Devices Input Devices API Function.
Geometrical Transformations 2 Adapted from Fundamentals of Interactive Computer Graphics, Foley and van Dam, pp , by Geb Thomas.
Transformation.
1/50 CS148: Introduction to Computer Graphics and Imaging Transforms CS148: Introduction to Computer Graphics and Imaging Transforms.
2 COEN Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric.
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.
Affine Transformation. Affine Transformations In this lecture, we will continue with the discussion of the remaining affine transformations and composite.
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
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.
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.
CSCE 441 Computer Graphics: 2D Transformations
Transformations. Transformations Introduce standard transformations ◦ Rotation ◦ Translation ◦ Scaling ◦ Shear Derive homogeneous coordinate transformation.
Modeling Transformation
Forward Projection Pipeline and Transformations CENG 477 Introduction to Computer Graphics.
Modeling Transformations
Transforms.
Camera Position (5.6) we specify the position and orientation of the camera to determine what will be seen. use gluLookAt (eye x, y, z, at x, y, z, up.
Geometric Transformations Hearn & Baker Chapter 5
2D Geometric Transformations
2D Imaging and Transformation
Summary of Properties of 3D Affine Transformations
Review: Transformations
3D Geometric Transformations
Computer Graphics Transformations.
Introduction to Computer Graphics CS 445 / 645
Review: Transformations
Chapter 4/5 glMatrixMode Modeling Transformations glTranslate glScale
Three-Dimensional Graphics
Transformations in OpenGL
Geometric Objects and Transformations (II)
TWO DIMENSIONAL TRANSFORMATION
Lecture #6 2D Geometric Transformations
Hierarchical Modeling
CSCE 441: Computer Graphics: Hierarchical Models
Presentation transcript:

2IV60 Computer Graphics 2D transformations Jack van Wijk TU/e

Overview Why transformations? Basic transformations: translation, rotation, scaling Combining transformations homogenous coordinates, transform. Matrices First 2D, next 3D

Transformations instantiation… world train animation… viewing… wheel image instantiation… world train animation… wheel viewing… modelling…

Why transformation? Model of objects Viewing Animation world coordinates: km, mm, etc. Hierarchical models:: human = torso + arm + arm + head + leg + leg arm = upperarm + lowerarm + hand … Viewing zoom in, move drawing, etc. Animation

Translation Translate over vector (tx, ty) x’=x+ tx, y’=y+ ty or y P+T H&B 7-1:220-222

Translation polygon Translate polygon: Apply the same operation on all points. Works always, for all transformations of objects defined as a set of points. y T x H&B 7-1:220-222

Rotation y y P’ a P x x H&B 7-1:222-223

Rotation around a point Q y y P’ a P PQ Q x x H&B 7-1:222-223

Scaling Schale with factor sx and sy: x’= sx x, y’= sy y or y P’ P Q’ H&B 7-1:224-225

Scaling with respect to a point F Scale with factors sx and sy: Px’= sx Px, Py’= syPy With respect to F: Px’  Fx = sx (Px  Fx), Py’  Fy = sy (Py  Fy) or Px’= Fx + sx (Px  Fx), Py’= Fy + sy (Py  Fy) y P’ P PF Q’ F Q x x H&B 7-1:224-225

Transformations Translate with V: Schale with factor sx = sy =s: T = P + V Schale with factor sx = sy =s: S = sP Rotate over angle a: R’x = cos a Px  sin a Py R’y = sin a Px + cos a Py x y P T S R H&B 7-2:225-228

Transformations… Messy! Transformations with respect to points: even more messy! How to combine transformations? H&B 7-2:225-228

Homogeneous coordinates 1 Uniform representation of translation, rotation, scaling Uniforme representation of points and vectors Compact representation of sequence of transformations H&B 7-2:225-228

Homogeneous coordinaten 2 Add extra coordinate: P = (px , py , ph) 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 H&B 7-2:225-228

Translation matrix H&B 7-2:225-228

Rotation matrix H&B 7-2:225-228

Scaling matrix H&B 7-2:225-228

Inverse transformations H&B 7-3:228

Combining transformations 1 H&B 7-4:228-229

Combining transformations 2 H&B 7-4:229

Combining transformations 3 H&B 7-4:229

Rotation around a point 1 1) 2) 3) H&B 7-4:229-230

Rotation around a point 2 1) 2) 3) H&B 7-4:229-230

Rotation around point 3 R 1) 2) 3) H&B 7-4:229-230

Rotation around point 4 R 1) 2) 3) H&B 7-4:229-230

Scaling w.r.t. point 1 F 1) 2) 3) H&B 7-4:230-231

Scaling w.r.t.point 2 F 1) 2) 3) H&B 7-4:230-231

Scaling w.r.t.point 3 F 1) 2) 3) H&B 7-4:230-231

Scale in other directions 1 1) 2) 3) H&B 7-4:230-231

Scale in other directions 2 1) 2) 3) H&B 7-4:230-231

Scale in other directions 3 1) 2) 3) H&B 7-4:230-231

Order of transformations 1 Rotation, translation… Translation, rotation… x’’ y’’ x’’ y’’ x’ y’ x’ y’ x y x y Matrix multiplication does not commute. The order of transformations makes a difference! H&B 7-4:232

Order of transformations 2 Pre-multiplication: P’ = M n M n-1…M 2 M 1 P Transformation M n in global coordinates Post-multiplication: P’ = M 1 M 2…M n-1 M n P Transformation M n in local coordinates: the coordinate system after application of M 1 M 2…M n-1 H&B 7-4:232

Order of transformations 3 OpenGL: glRotate, glScale, etc.: Post-multiplication of current transformation matrix Always transformation in local coordinates Global coordinate version: read in reverse order H&B 7-4:232

Order of transformations 4 Local transformations: Global transformations: x’’ y’’ x’’ y’’ x’ y’ x’ y’ x y x y Local trafo interpretation Global trafo interpretation glTranslate(…); glRotate(…); H&B 7-4:232

Matrices in general rotation and scaling translation H&B 7-4:233-235

Direct construction of matrix If you know the target frame: Construct matrix directly. Define shape in nice local u,v coordinates, use matrix transformation to put it in x,y space. y v u B A T x H&B 7-4:233-235

Direct construction of matrix If you know the target frame: Construct matrix directly. y v u B A T x H&B 7-4:233-235

Rigid body transformation only rotation translation y u v B A T x H&B 7-4:233-235

Other 2D transformations Reflection Shear Can also be combined H&B 7-4:240

Reflection over axis Reflext over x-axis: x’= x, y’= y or y x H&B 7-4:240-242

Reflect over origin Reflect over origin: x’= x, y’=  y or y x H&B 7-4:240-242

Shear Shear the y-as: x’=x+fy, y’=y or y  x H&B 7-4:242-243

Transformations coordinates Given (x,y)-coordinates, Find (x’,y’)-coordinates. Reverse route as object transformaties. y y’ x’ q (x0, y0) x H&B 7-8:246-248

Transformations coordinates Given (x,y)-coordinates, Find (x’,y’)-coordinates. Example: user points at (x,y), what’s the position in local coordinates? y y’ x’ q (x0, y0) x H&B 7-8:246-248

Transformations coordinates Given X: (x,y)-coordinates, Find X’: (x’,y’)-coordinates. Standard: X=MX’ (object trafo: from local to global) Here: X’=M-1X (from global to local) y y’ x’ q (x0, y0) x H&B 7-8:246-248

Transformations coordinates Given X: (x,y)-coordinates, Find X’: (x’,y’)-coordinates. Here: X’=M-1X (from global to local) Approach 1: - Determine “standard matrix” M (from local to global coordinates) and invert y y’ x’ q (x0, y0) x H&B 7-8:246-248

Transformations coordinates Given X: (x,y)-coordinates, Find X’: (x’,y’)-coordinates. Here: X’=M-1X (from global to local) Approach 2: construct transformation that maps local frame to global (reverse of usual). y y’ x’ q (x0, y0) x H&B 7-8:246-248

Transformations coordinates Given X: (x,y)-coordinates, Find X’: (x’,y’)-coordinates. Here: X’=M-1X (from global to local) Approach 2: Translate (x0, y0) to origin; Rotate x’-axis to x-axis. y y’ x’ q (x0, y0) x H&B 7-8:246-248

Transformations coordinates Given X: (x,y)-coordinates, Find X’: (x’,y’)-coordinates. Here: X’=M-1X (from global to local) Approach 2: M-1 = R()T(x0, y0) y y’ x’ q (x0, y0) x H&B 7-8:246-248

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. H&B 7-9:248-253

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) H&B 7-9:248-253

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); H&B 7-9:248-253

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); H&B 7-9:248-253

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 H&B 9-8:324-327

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, 0.5); 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(); Shorter, more robust H&B 9-8:324-327 Undo transformation

2D transformations summarized Transformations: modeling, viewing, animation; Several kinds of transformations; Homogeneous coordinates; Combine transformations using matrix multiplication. Up to 3D!