CS 450: Computer Graphics 2D TRANSFORMATIONS

Slides:



Advertisements
Similar presentations
CS 450: COMPUTER GRAPHICS LINEAR ALGEBRA REVIEW SPRING 2015 DR. MICHAEL J. REALE.
Advertisements

COMPUTER GRAPHICS 2D TRANSFORMATIONS.
Computer Graphics Lecture 4 Geometry & Transformations.
1 Computer Graphics Chapter 6 2D Transformations.
Two-Dimensional Geometric Transformations
CMPE 466 COMPUTER GRAPHICS
Transformations II Week 2, Wed Jan 17
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Transformations II Week.
HCI 530 : Seminar (HCI) Damian Schofield. HCI 530: Seminar (HCI) Transforms –Two Dimensional –Three Dimensional The Graphics Pipeline.
2D Geometric Transformations
Linear Algebra and SVD (Some slides adapted from Octavia Camps)
CS 376 Introduction to Computer Graphics 02 / 09 / 2007 Instructor: Michael Eckmann.
1 CSCE 441 Computer Graphics: 2D Transformations Jinxiang Chai.
3-D Geometry.
Computer Graphics (Fall 2008) COMS 4160, Lecture 3: Transformations 1
Transformations CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Computer Graphics (Fall 2004) COMS 4160, Lecture 3: Transformations 1
2D Transformations Unit - 3. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale it.
3D Graphics Goal: To produce 2D images of a mathematically described 3D environment Issues: –Describing the environment: Modeling (mostly later) –Computing.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology 3D Engines and Scene Graphs Spring 2012.
CS 450: COMPUTER GRAPHICS 3D TRANSFORMATIONS SPRING 2015 DR. MICHAEL J. REALE.
Foundations of Computer Graphics (Fall 2012) CS 184, Lecture 3: Transformations 1
Mathematical Fundamentals
Transformations Aaron Bloomfield CS 445: Introduction to Graphics
CS 480/680 Computer Graphics Representation Dr. Frederick C Harris, Jr. Fall 2012.
Geometric Transformation. So far…. We have been discussing the basic elements of geometric programming. We have discussed points, vectors and their operations.
Transformation of Graphics
Transformations Dr. Amy Zhang.
CS 480/680 Computer Graphics Transformations Dr. Frederick C Harris, Jr.
2D Transformation of Graphics
Dx = 2 dy = 3 Y X D Translation A translation is applied to an object by repositioning it along a straight-line path.
Part7: Geometric Transformations
CSE 681 Review: Transformations. CSE 681 Transformations Modeling transformations build complex models by positioning (transforming) simple components.
Transformations Jehee Lee Seoul National University.
Geometric Transformations
CS 376 Introduction to Computer Graphics 02 / 16 / 2007 Instructor: Michael Eckmann.
Jinxiang Chai CSCE441: Computer Graphics 3D Transformations 0.
Jinxiang Chai Composite Transformations and Forward Kinematics 0.
Computer Graphics 2D Transformations. 2 of 74 Contents In today’s lecture we’ll cover the following: –Why transformations –Transformations Translation.
Geometric Objects and Transformation
CS559: Computer Graphics Lecture 8: 3D Transforms Li Zhang Spring 2008 Most Slides from Stephen Chenney.
Transformation.
CS559: Computer Graphics Lecture 8: Warping, Morphing, 3D Transformation Li Zhang Spring 2010 Most slides borrowed from Yungyu ChuangYungyu Chuang.
Two-Dimensional Geometric Transformations ch5. 참조 Subjects : Basic Transformations Homogeneous Coordinates Composite Transformations Other 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.
Geometric Transformations Hearn & Baker Chapter 5 Some slides are taken from Robert Thomsons notes.
Geometric Transformations
Transformations CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
Geometric Transformations Sang Il Park Sejong University Many slides come from Jehee Lee’s.
3D Transformation A 3D point (x,y,z) – x,y, and z coordinates
Affine Geometry.
Foundations of Computer Graphics (Spring 2012) CS 184, Lecture 3: Transformations 1
Learning Objectives Affine transformations Affine transformations Translation Translation Rotation Rotation Scaling Scaling Reflection Reflection Shear.
CS559: Computer Graphics Lecture 9: 3D Transformation and Projection Li Zhang Spring 2010 Most slides borrowed from Yungyu ChuangYungyu Chuang.
Jinxiang Chai CSCE441: Computer Graphics 3D Transformations 0.
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.
CS 325 Introduction to Computer Graphics 02 / 19 / 2010 Instructor: Michael Eckmann.
Matrix Transformations Reference: “3D Math Primer for Graphics and Game Development” – , , , , 9.4
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
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.
Transforms.
Geometric Transformations Hearn & Baker Chapter 5
Computer Graphics CC416 Week 15 3D Graphics.
Introduction to Computer Graphics CS 445 / 645
COMP 175: Computer Graphics February 9, 2016
Chapter IV Spaces and Transforms
2D Geometric Transformations
TWO DIMENSIONAL TRANSFORMATION
Presentation transcript:

CS 450: Computer Graphics 2D TRANSFORMATIONS Spring 2015 Dr. Michael J. Reale

INTRODUCTION Now that we have some linear algebra under our respective belts, we can start using it in graphics! So far, for each primitive, we have a description that includes the positions of the vertices  model coordinates Examples: A square with vertices (-1,-1), (1,-1), (1,1), (-1,1) A teapot with its vertices relative to its bottom We would like to be able to place this primitive in the world wherever we want (as well as rotate it and/or scale it)  use a model transform Recall: Model coordinates (relative to model)  MODEL TRANSFORM  World coordinates We would also like to be able to get the world coordinates relative to the camera  use view transform Recall: World coordinates  VIEW TRANSFORM  Camera (Eye) Coordinates

TRANSFORMATIONS Transformations or transforms = operations that change position, orientation, and/or size of geometric object Use matrices to perform transformations on vectors/points Examples: model transforms, the view transform, projection transform, etc. Geometric vs. Modeling transformation Sometimes considered the same Sometimes: Geometric = transforming the whole “object” Modeling = gives hierarchy for pieces of the object (e.g., arms relative to torso in human body model)

OVERVIEW Three most basic transformations: Rotation Scaling (i.e., resizing the object) Translation (i.e., moving/placing the object) Other transformations: shear, reflection, etc. We’re going to start with 2D transformations first Then, later, we’ll move on to 3D transformations Keep in mind, we will be building simple transformations (with certain implicit assumptions) However, we will combine these to make more powerful transformations

ROTATION

ROTATION: INTRODUCTION To rotate an object, we need: Rotation angle  how much to rotate Counterclockwise in plane we’re rotating Rotation axis  what we’re rotating around In 2D, just use z axis WARNING: Rotation performed around ORIGIN Origin (0,0) = rotation point (or pivot point) (We’ll talk later about how to rotate around an arbitrary rotation point)

ROTATION: DERIVING Recall: P = (x,y)  original point P’ = (x’,y’)  transformed point ϕ = original angle of point (x,y) from x axis θ = difference in angle between old and new point So, our original point (x,y) and transformed point (x’,y’) in polar coordinates are as follows  After substitution, we can express the transformed point in terms of θ only:

ROTATION MATRIX We have: If our rotation matrix transform is R, then: Therefore, our 2D rotation matrix is:

SCALING

SCALING: INTRODUCTION Scaling an object = altering the size of an object The scaling we will be doing here  simply multiplying each coordinate by a scaling factor: The corresponding scaling matrix transformation 

SCALING: FACTORS Scaling factor > 1.0  enlarge Scaling factor < 1.0  shrink Scaling factor < 0  negative scaling  resizes AND reflects object Uniform scaling = scaling factors are all the same (e.g., sx = sy) Otherwise, called differential scaling

SCALING: ASSUMPTIONS WARNING: Because of the way we are doing scaling: Only scaling in X or Y direction (or both), but NOT in arbitrary direction! Scaling relative to ORIGIN! ORIGIN = fixed point (point unaffected by scaling) (We’ll talk later about how to use a different fixed point)

TRANSLATION

TRANSLATION: INTRODUCTION Translation = moving a point by a certain distance (tx , ty) (tx , ty) = translation distances = translation vector = shift vector If we’re stuck with 2x2 matrices and 2x1 vectors, we have to add vectors to perform a translation:

TRANSLATION: PROBLEM At some point, we would like to be able to combine multiple transformations into a single matrix: This means we can multiply all our transformations together first (M), and then apply it to each point we want HOWEVER, because translation is handled as addition, we need to compute intermediate steps:

HOMOGENEOUS COORDINATES

HOMoGENEOUS COORDINATES To fix this, we will extend our 2x2 matrices (and our 2x1 vectors) to 3x3 matrices (and to 3x1 vectors) Homogeneous coordinates = for 2D coordinates, extension to (xh , yh , h) h = homogeneous parameter  nonzero value such that: Often just set h = 1  (x, y) becomes (x, y, 1) Often use “w” instead of “h” (especially for 3D vectors  (x,y,z,w) ) As we’ll see, this allows us to represent translation as a matrix multiplication!

TRANSLATION MATRIX WITH HOMOGENEOUS COORDINATES The 2D translation matrix is sometimes represented as T(tx , ty )

ROTATION MATRIX WITH HOMOGENEOUS COORDINATES The 2D rotation matrix is sometimes represented as R(θ)

SCALING MATRIX WITH HOMOGENEOUS COORDINATES The 2D scaling matrix is sometimes represented as S(sx , sy)

PATTERN WITH HOMOGENEOUS COORDINATE MATRICES With the translation matrix, we purposely use the additional elements of the matrix (in this case, the extra column): For rotation, scaling, and shear matrices (discussed later), the original matrix is augmented with an extra row and column of zeros (except for the last (row,column) position, which is set to 1):

HOMOGENEOUS COORDINATES: POINTS VS. VECTORS Recall: a vector can also be interpreted as: Location (w = 1) Direction (w = 0) …in space Note: sometimes, location  called “point” and direction  called “vector” Depending on how we want to interpret the vector, we will set a different value for w

HOMOGENEOUS COORDINATES: POINTS VS. VECTORS Points  all transformations should have an effect (translation, rotation, scaling, etc.) w set to 1 Direction  translation has no meaning (other transformation should work though) w set to 0

INVERSE TRANSFORMATIONS

INVERSE TRANSFORMATIONS Fortunately, the inverses of the translation, rotation, and scaling matrices can be computed directly: Applying an inverse transformation  does the opposite transformation T-1  translate object (-tx , -ty )

QUICK ASIDE: INVERSE OF ROTATION MATRIX We computed the inverse directly by using the negative angle (-θ)  only sine was affected by this It turns out, any rotation matrix is ORTHOGONAL  inverse = transpose = swapping rows and columns Also note: |R| = cos2 θ + sin2 θ = 1

CHANGING COORDINATE SYSTEMS

CHANGING 2D COORDINATE SYSTEMS Given a point P, many times we want to get the coordinates of this point relative to some OTHER coordinate basis vectors and origin point Example: viewing transform  getting coordinates with respect to camera’s view (camera’s basis vectors) and camera’s starting point (camera’s origin) As with all our slides thus far, we’ll stick to 2D for now. For a 2D coordinate system, we need: An origin point (x0, y0) Two axes  x’ and y’

CHANGING 2D COORDINATE SYSTEMS To change 2D coordinate systems: Translate so that the new origin is at (0,0)  T(-x0, -y0) Rotate the x’ axis onto the x axis  need to get angle θ between x’ and x  R(-θ) Final transformation: R(-θ) T(-x0, -y0)

COMPUTING NEW COORDINATE AXES If we only know one vector V (and we want y’ to point in the same direction): Alternatively, we might be given P0 (origin) and P1 (endpoint of y’ axis):

CHANGING 2D COORDINATE AXES ONLY If our new coordinate axes are u = (ux, uy) and v = (vx, vy), then we can construct the ROTATION matrix directly: When multiplying by a point P, P will be projected on each axis (P dotted with each axis):

CHANGING 2D COORDINATE AXES ONLY Recall: CHANGING 2D COORDINATE AXES ONLY To drive the point home:

“UNDOING” a 2D COORDINATE AXIS CHANGE To go back to the standard basis, we need to get the original coordinates back To get the x coordinate  P’x * ux + P’y * vx  P’x * x’ To get the y coordinate  P’x * uy + P’y * vy  P’y * y’ The matrix form becomes:

“UNDOING” a 2D COORDINATE AXIS CHANGE Note: If coordinate axes are orthonormal  matrix R is orthogonal  R-1 = RT

COMPOSITE TRANSFORMATIONS

COMPOSITE TRANSFORMATIONS Composite transformation matrix = product of individual transformations Process of forming one is called concatenation or composition of matrices Example: apply M1 then M2  M = M2M1 NOTE THE ORDER! Must multiply from RIGHT to LEFT!!!

WHY USE COMPOSITE TRANSFORMATIONS? There are a LOT of different things you can do with these; we’ll talk about a few very common examples: Rotation around an arbitrary pivot point Scaling around an arbitrary fixed point Scaling in an arbitrary direction

ROTATION AROUND AN ARBITRARY PIVOT POINT Let’s say we want to rotate around an pivot point (px , py) Basic idea: Translate (-px , -py)  (px , py) is now at origin Rotate points Translate back to (px , py)

Scaling around an arbitrary fixed point Say we want to scale an object relative a fixed point (px , py) Basic idea: Translate (-px , -py)  (px , py) is now at origin Scale points Translate back to (px , py)

Scaling in an arbitrary direction Let’s assume our fixed point is already at the origin Basic idea: Rotate our arbitrary axis u into the x axis Scale along x Rotate back If u is our x’ axis, then our y’ axis = v = (-uy , ux):

ORDER MATTERS! What order you apply your matrices will affect what transformations you perform!!! Example: rotation then scale vs. scale then rotation First transformation  RIGHT-most matrix when multiplying!

RIGID-BODY TRANSFORMATIONS

RIGID-BODY TRANSFORMATIONS Rigid-body transformation = only includes translation and/or rotation All angles and distances between coordinate positions preserved Intuitively, object doesn’t change shape  only changes position and/or orientation Also called a rigid-motion transformation In 2D, has the general form: WARNING: (trx , try) != (tx , ty ) from earlier! (Depends on order of transformations) Upper-left 2x2 matrix  orthonormal vector set

OTHER TRANSFORMATIONS (REFLECTION AND SHEAR)

REFLECTION TRANSFORMATION Reflection transformation = transformation that produces a mirror image of object In 2D  180° rotation about axis of reflection axis Reflection about line y = 0 (x axis): Reflection about line x = 0 (y axis): Reflection about origin:

REFLECTION ACROSS DIAGONALS Reflection across y = x: Reflection across y = -x:

SHEAR TRANSFORMATION Shear transformation = distorts shape of object like as if the object is composed of layers sliding over each other Shear in x-direction: Shear in y-direction:

SHEAR TRANSFORMATION WARNING: By default, assumes reference line is either the x axis or the y axis (for the x-shear and y- shear, respectively)