Computer Graphics 2D Transformations

Slides:



Advertisements
Similar presentations
Computer Graphics: 2D Transformations
Advertisements

Gursharan Singh Tatla TRANSFORMATIONS Gursharan Singh Tatla Gursharan Singh Tatla.
Computer Graphics Lecture 4 Geometry & Transformations.
Geometric Transformations
1 Computer Graphics Chapter 6 2D Transformations.
CMPE 466 COMPUTER GRAPHICS
HCI 530 : Seminar (HCI) Damian Schofield. HCI 530: Seminar (HCI) Transforms –Two Dimensional –Three Dimensional The Graphics Pipeline.
2D Geometric Transformations
University of North Carolina at Greensboro
1 CSCE 441 Computer Graphics: 2D Transformations Jinxiang Chai.
2.1 si SI31 Advanced Computer Graphics AGR Lecture 2 Basic Modelling.
Course Website: Computer Graphics 3: 2D Transformations.
Computer Graphics with OpenGL 3e
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.
Geometric Transformation-2D
2D Transformations Unit - 3. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale it.
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.
Lecture Notes: Computer Graphics.
Dx = 2 dy = 3 Y X D Translation A translation is applied to an object by repositioning it along a straight-line path.
Computer Graphics 2D Transformations. 2 of 74 Contents In today’s lecture we’ll cover the following: –Why transformations –Transformations Translation.
Two-Dimensional Geometric Transformations ch5. 참조 Subjects : Basic Transformations Homogeneous Coordinates Composite Transformations Other Transformations.
1 Graphics CSCI 343, Fall 2015 Lecture 10 Coordinate Transformations.
2D Geometric Transformation Translation A translation is applied to an object by repositioning it along a straight-line path from one coordinate location.
Transformations of objects
Graphics Lecture 2: Slide 1 Lecture 2 Transformations for animation.
Computer Graphics I, Fall 2010 Transformations.
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.
Computer Graphic 2 D Transformation.
CSCE 441 Computer Graphics: 2D Transformations
Modeling Transformation
Transformations. Modeling Transformations  Specify transformations for objects  Allows definitions of objects in own coordinate systems  Allows use.
Instructor: Dr. Shereen Aly Taie Basic Two-Dimensional Geometric Transformation 5.2 Matrix Representations and Homogeneous Coordinates 5.3 Inverse.
Transformations University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2016 Tamara Munzner.
Objectives Introduce standard transformations Introduce standard transformations Derive homogeneous coordinate transformation matrices Derive homogeneous.
CPT450 – Computer Graphics
Lecture 5 Basic geometric objects
Modeling Transformations
Transforms.
Geometric Transformations
Computer Graphics 3: 2D Transformations
Geometric Transformations Hearn & Baker Chapter 5
2D TRANSFORMATIONS.
2D Transformations By: KanwarjeetSingh
Computer Graphics CC416 Week 15 3D Graphics.
Computer Graphics Transformations.
2D Transformations with Matrices
Computer Graphics 3: 2D Transformations
Review: Transformations
Computer Graphics 3D Transformations
3D Geometric Transformations
Chapter 5 2-D Transformations.
Computer Graphics Transformations.
Image Warping (Geometric Transforms)
Introduction to Computer Graphics CS 445 / 645
Review: Transformations
2D Transformations y y x x y x.
Line and Character Attributes 2-D Transformation
© 2008, Fayyaz A. Afsar, DCIS, PIEAS.
COMP 175: Computer Graphics February 9, 2016
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Transformations.
2-D Geometry.
Transformations 3 University of British Columbia
Computer Graphics Lecture 12 2D Transformations II Taqdees A
Chapter IV Spaces and Transforms
2D Geometric Transformations
Rendering – Matrix Transformations and the Graphics Pipeline
TWO DIMENSIONAL TRANSFORMATION
Translation in Homogeneous Coordinates
Presentation transcript:

Computer Graphics 2D Transformations

Contents In today’s lecture we’ll cover the following: Why transformations Transformations Translation Scaling Rotation Homogeneous coordinates Matrix multiplications Combining transformations

Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale it and rotate it Images taken from Hearn & Baker, “Computer Graphics with OpenGL” (2004)

Transformations A transformation on an object is an operation that changes how the object is finally drawn to screen There are two ways of understanding a transformation An Object Transformation alters the coordinates of each point according to some rule, leaving the underlying coordinate system unchanged A Coordinate Transformation produces a different coordinate system, and then represents all original points in this new system

Example: OBJECT TRANSFORMATION {.4, 2} {1,1} Example: COORDINATE TRANSFORMATION {1,1} {1,1} More on this later…

Transformations Whole collections of points may be transformed by the same transformation T, e.g. lines or circles The image of a line, L, under T, is the set of all images of the individual points of L. For most mappings of interest, this image is still a connected curve of some shape For some mappings, the result of transforming a line may no longer be a line Affine Transformations, however, do preserve lines, and are the most commonly-used transformations in computer graphics P1 {0, 2} P2 {2, 2} P0 {0, 0} P3 {2, 0} Q1 {0, 4} Q2 {4, 4} Q3 {4, 0} Q0 {0, 0}

Useful Properties of Affine Transformations Preservation of lines: Preservation of parallelism Preservation of proportional distances

Why are they useful? They preserve lines, so the image of a straight line is another straight line. This vastly simplifies drawing transformed line segments. We need only compute the image of the two endpoints of the original line and then draw a straight line between them Preservation of co-linearity guarantees that polygons will transform into polygons Preservation of parallelism guarantees that parallelograms will transform into parallelograms Preservation of proportional distances means that mid-points of lines remain mid-points

Elementary Transformations Affine transformations are usually combinations of four elementary transformations: 1: Translation 2: Scaling 3: Rotation 4: Shearing

Translation Simply moves an object from one position to another xnew = xold + tx ynew = yold + ty (tx,ty) is the translation vector or shift vector Note: House shifts position relative to origin y x 1 2 3 4 5 6 7 8 9 10

Translation A translation moves an object into a different position in a scene This is achieved by adding an offset/translation vector In Vector notation: t Translate by t Original points Transformed points

Translation P/ = P + T

Scaling (Sx, Sy) are the scaling factors Scaling multiplies all coordinates Alters the size of an object WATCH OUT: Objects grow and move! xnew = Sx × xold ynew = Sy × yold (Sx, Sy) are the scaling factors Note: House shifts position relative to origin y x 1 2 3 4 5 6 7 8 9 10

Translation P/ = S.P Sx = Sy Uniform scaling Sx = Sy Differential scaling

Scaling A scaling changes the size of an object with two scale factors, Sx and Sy (if Sx != Sy, then we have a non-uniform scale) Sx, Sy Scale by Sx, Sy Original points Transformed points

Fixed Point Scaling The location of a scaled object can be controlled by choosing a position, called the fixed point,(xf, yf) i.e., to remain unchanged after the scaling transformation. The fixed point can be chosen as the objects’ centroid or any other position For a vertex with coordinates (x, y), the scaled coordinates (x/, y/) are calculated as, x/= xf + (x – xf)sx y/= yf + (y – yf)sy x/= x. sx + xf (1 – sx) and y/= y. sy + yf (1 – sy) Where xf (1 – sx) and yf (1 – sy) are constants for all points in the object.

Rotation To generate a rotation, a rotation angle θ and the position (xr, yr ) of the rotation point is needed xnew = r × cos(δ + θ) = r cosδ cosθ – r sin δ sinθ ynew = r × sin(δ + θ) = r cosδ sinθ + r sin δ cosθ Original polar coordinates xold = r cos δ and yold = r sin δ y 6 5 4 3 2 1 δ x 1 2 3 4 5 6 7 8 9 10

Rotation Rotates all coordinates by a specified angle xnew = xold × cosθ – yold × sinθ ynew = xold × sinθ + yold × cosθ Points are always rotated about the origin For rotation about any specified point (xr, yr): xnew = xr + (xold - xr)× cosθ – (yold - yr)× sinθ ynew = yr + (xold - xr)× sinθ + (yold - yr)× cosθ y 6 5 4 3 2 1 x 1 2 3 4 5 6 7 8 9 10

Rotation equations can be written in the matrix form as P/ = R. P Where rotation matrix When coordinate positions are represented as row vectors instead of column vectors, the matrix product in rotation eqn (i) is transposed so that the trnsformed row coordinate [x’ y’] is calculated as P/ T = (R. P)T = PT.RT Where PT = [ x y ], and the transpose matrix RT of matrix R is obtained by interchanging rows & columns.

Rotation Using the trigonometric relations, a point rotated by an angle q about the origin is given by the following equations: So q Rotate by q Original points Transformed points

Rotation - derivation Q P [1] [2] [3] [4] PY [1] PX R Substituting from [3] and [4]… Similarly from [2]… Background info

Shearing A shearing affects an object in a particular direction (in 2D, it’s either in the x or in the y direction) A shear in the x direction would be as follows: The quantity h specifies what fraction of the y-coordinate should be added to the x-coordinate, and may be positive or negative More generally: a simultaneous shear in both the x and y directions would be

Shearing g =0, h=0.5 g=0.5, h=0.5 Shear by {g,h} Original points Transformed points g=0.5, h=0.5 Shear by {g,h} Original points Transformed points

Matrix Representation All affine transformations in 2D can be generically described in terms of a generic equation as follows: i.e.

Transformations Summary 1: Translation 2: Scaling 3: Rotation 4: Shearing T T T T

Problem An affine transformation is composed of a linear combination followed by a translation Unfortunately, the translation portion is not a matrix multiplication but must instead be added as an extra term, or vector – this is inconvenient

Homogeneous Coordinates A point (x, y) can be re-written in homogeneous coordinates as (xh, yh, h) The homogeneous parameter h is a non- zero value such that: We can then write any point (x, y) as (h.x, h.y, h) We can conveniently choose h = 1 so that (x, y) becomes (x, y, 1)

Why Homogeneous Coordinates? Mathematicians commonly use homogeneous coordinates as they allow scaling factors to be removed from equations We will see in a moment that all of the transformations we discussed previously can be represented as 3*3 matrices Using homogeneous coordinates allows us use matrix multiplication to calculate transformations – extremely efficient!

Homogeneous Coordinates The “trick” we use is to add an additional component 1 to both P and Q, and also a third row and column to M, consisting of zeros and a 1 i.e. Rotate by q: Translation by {tx, ty} Scale by Sx, Sy Shear by g, h:

Homogeneous Translation The translation of a point by (dx, dy) can be written in matrix form as: Representing the point as a homogeneous column vector we perform the calculation as:

Remember Matrix Multiplication Recall how matrix multiplication takes place:

Homogenous Coordinates To make operations easier, 2-D points are written as homogenous coordinate column vectors Translation: Scaling:

Homogenous Coordinates (cont…) Rotation:

Inverse Transformations Transformations can easily be reversed using inverse transformations

Composite Transformations Translations If 2 successive translation vectors (dx1, dy1) and (dx2, dy2) are applied to a coordinate position V, the final transformed location V/ is calculated as Where P and P/ are represented as homogeneous coordinate column vectors. Which demonstrates that 2 successive translations are additive

Composite Transformations Rotations If 2 successive rotation vectors are applied to a coordinate position V, the final rotated location V/ is calculated as By multiplying the 2 rotation matrices, we can verify that 2 scuccessive rotations are additive:. So that the final rotated coordinates can be calculated with the composite matrix as

Composite Transformations Scalings Concatenating transformation matrices for 2 successive scaling operations produces the following composite scaling matrix: Which demonstrates that 2 successive scalings are multiplicative. Thus if we were to triple the size of an object twice in succession, the final size would be nine times that of the original.

Combining Transformations A number of transformations can be combined into one matrix to make things easy Allowed by the fact that we use homogenous coordinates Imagine rotating a polygon around a point other than the origin Transform to centre point to origin Rotate around origin Transform back to centre point

Combining Transformations (cont…) 1 2 3 4

Combining Transformations (cont…) The three transformation matrices are combined as follows REMEMBER: Matrix multiplication is not commutative so order matters

Summary In this lecture we have taken a look at: 2D Transformations Translation Scaling Rotation Homogeneous coordinates Matrix multiplications Combining transformations Next time we’ll start to look at how we take these abstract shapes etc and get them on-screen

Exercises 1 Translate the shape below by (7, 2) y (2, 3) (1, 2) (3, 2) 1 2 3 4 5 6 7 8 9 10 (2, 3) (1, 2) (3, 2) (2, 1) x

Exercises 2 Scale the shape below by 3 in x and 2 in y y (2, 3) (1, 2) 1 2 3 4 5 6 7 8 9 10 (2, 3) (1, 2) (3, 2) (2, 1) x

Exercises 3 Rotate the shape below by 30° about the origin y (7, 3) 1 2 3 4 5 6 7 8 9 10 (7, 3) (6, 2) (8, 2) (7, 1) x

Exercise 4 Write out the homogeneous matrices for the previous three transformations Translation Scaling Rotation

Exercises 5 Using matrix multiplication calculate the rotation of the shape below by 45° about its centre (5, 3) x y 1 2 3 4 5 6 7 8 9 10 (5, 4) (6, 3) (4, 3) (5, 2)

Scratch y 1 2 3 4 5 6 7 8 9 10 x

Equations xnew = xold + dx ynew = yold + dy Translation: Scaling: xnew = Sx × xold ynew = Sy × yold Rotation xnew = xold × cosθ – yold × sinθ ynew = xold × sinθ + yold × cosθ