CS 4204 Computer Graphics

Similar documents
Computer Graphics Labs

Given a point cloud, polygon, or sampled parametric curve, we can use transformations for several purposes:

Lecture 3: Coordinate Systems and Transformations

Aston University. School of Engineering & Applied Science

2D Geometrical Transformations. Foley & Van Dam, Chapter 5

2D Geometric Transformations

Vector Notation: AB represents the vector from point A to point B on a graph. The vector can be computed by B A.

Graphics Pipeline in a Nutshell

9 MATRICES AND TRANSFORMATIONS

3D Tranformations. CS 4620 Lecture 6. Cornell CS4620 Fall 2013 Lecture Steve Marschner (with previous instructors James/Bala)

4BA6 - Topic 4 Dr. Steven Collins. Chap. 5 3D Viewing and Projections

TWO-DIMENSIONAL TRANSFORMATION

Rotation Matrices and Homogeneous Transformations

Geometric Transformations

Transformations in the pipeline

Geometric Transformation CS 211A

Essential Mathematics for Computer Graphics fast

Solving Simultaneous Equations and Matrices

Geometry for Computer Graphics

Lecture Notes. Fundamentals of Computer Graphics. Prof. Michael Langer School of Computer Science McGill University

Affine Transformations

Realtime 3D Computer Graphics Virtual Reality

Vector Math Computer Graphics Scott D. Anderson

Lecture L3 - Vectors, Matrices and Coordinate Transformations

CS 4204 Computer Graphics

Geometric Transformations

Fundamentals of Computer Animation

A vector is a directed line segment used to represent a vector quantity.

3D Viewing. Chapter 7. Projections. 3D clipping. OpenGL viewing functions and clipping planes

Android and OpenGL. Android Smartphone Programming. Matthias Keil. University of Freiburg

521493S Computer Graphics. Exercise 2 & course schedule change

THREE DIMENSIONAL GEOMETRY

December 4, 2013 MATH 171 BASIC LINEAR ALGEBRA B. KITCHENS

Monash University Clayton s School of Information Technology CSE3313 Computer Graphics Sample Exam Questions 2007

Introduction to Matrices for Engineers

Adding vectors We can do arithmetic with vectors. We ll start with vector addition and related operations. Suppose you have two vectors

x1 x 2 x 3 y 1 y 2 y 3 x 1 y 2 x 2 y 1 0.

CHAPTER FIVE. 5. Equations of Lines in R 3

South Carolina College- and Career-Ready (SCCCR) Pre-Calculus

Lectures notes on orthogonal matrices (with exercises) Linear Algebra II - Spring 2004 by D. Klain

GCE Mathematics (6360) Further Pure unit 4 (MFP4) Textbook

Algebra I Vocabulary Cards

Geometric Camera Parameters

Chapter 6. Linear Transformation. 6.1 Intro. to Linear Transformation

CLOUD DIGITISER 2014!

CSE 564: Visualization. GPU Programming (First Steps) GPU Generations. Klaus Mueller. Computer Science Department Stony Brook University

Mathematics Notes for Class 12 chapter 10. Vector Algebra

INTRODUCTION TO RENDERING TECHNIQUES

Unified Lecture # 4 Vectors

B4 Computational Geometry

Exam 1 Sample Question SOLUTIONS. y = 2x

We can display an object on a monitor screen in three different computer-model forms: Wireframe model Surface Model Solid model

Math 241, Exam 1 Information.

Geometry of Vectors. 1 Cartesian Coordinates. Carlo Tomasi

Linear algebra and the geometry of quadratic equations. Similarity transformations and orthogonal matrices

CMSC 425: Lecture 13 Animation for Games: Basics Tuesday, Mar 26, 2013

discuss how to describe points, lines and planes in 3 space.

Practice Final Math 122 Spring 12 Instructor: Jeff Lang

Dear Accelerated Pre-Calculus Student:

Vector has a magnitude and a direction. Scalar has a magnitude

28 CHAPTER 1. VECTORS AND THE GEOMETRY OF SPACE. v x. u y v z u z v y u y u z. v y v z

9.4. The Scalar Product. Introduction. Prerequisites. Learning Style. Learning Outcomes

Figure 1.1 Vector A and Vector F

How To Draw A Billiards Ball In Gta 3D With Texture Mapping (Gta 3) On A Computer Or 2D Or Gta 2D (Gt) On Your Computer Or Computer Or Your Computer (Or Your Computer)

Mathematics Course 111: Algebra I Part IV: Vector Spaces

Gerrit Stols

Chapter 11 Equilibrium

Solutions to Homework 10

Connecting Transformational Geometry and Transformations of Functions

13 MATH FACTS a = The elements of a vector have a graphical interpretation, which is particularly easy to see in two or three dimensions.

MAT188H1S Lec0101 Burbulla

Metrics on SO(3) and Inverse Kinematics

One advantage of this algebraic approach is that we can write down

2 Session Two - Complex Numbers and Vectors

Parametric Curves. (Com S 477/577 Notes) Yan-Bin Jia. Oct 8, 2015

Continued Fractions and the Euclidean Algorithm

BookTOC.txt. 1. Functions, Graphs, and Models. Algebra Toolbox. Sets. The Real Numbers. Inequalities and Intervals on the Real Number Line

IV. ALGEBRAIC CONCEPTS

v w is orthogonal to both v and w. the three vectors v, w and v w form a right-handed set of vectors.

MATH2210 Notebook 1 Fall Semester 2016/ MATH2210 Notebook Solving Systems of Linear Equations... 3

For example, estimate the population of the United States as 3 times 10⁸ and the

Introduction to 2D and 3D Computer Graphics Mastering 2D & 3D Computer Graphics Pipelines

Cabri Geometry Application User Guide

Physics 235 Chapter 1. Chapter 1 Matrices, Vectors, and Vector Calculus

Concepts in Calculus III

a 11 x 1 + a 12 x a 1n x n = b 1 a 21 x 1 + a 22 x a 2n x n = b 2.

Algebra 2 Chapter 1 Vocabulary. identity - A statement that equates two equivalent expressions.

3. KINEMATICS IN TWO DIMENSIONS; VECTORS.

Content. Chapter 4 Functions Basic concepts on real functions 62. Credits 11

Conjectures. Chapter 2. Chapter 3

CITY UNIVERSITY LONDON. BEng Degree in Computer Systems Engineering Part II BSc Degree in Computer Systems Engineering Part III PART 2 EXAMINATION

Section 1.1. Introduction to R n

The Use of Dynamic Geometry Software in the Teaching and Learning of Geometry through Transformations

TRIGONOMETRY FOR ANIMATION

Projective Geometry: A Short Introduction. Lecture Notes Edmond Boyer

NAKURU DISTRICT SEC. SCHOOLS TRIAL EXAM Kenya Certificate of Secondary Education MATHEMATICS PAPER2 2½ HOURS

A QUICK GUIDE TO THE FORMULAS OF MULTIVARIABLE CALCULUS

α = u v. In other words, Orthogonal Projection

Origins of the Unusual Space Shuttle Quaternion Definition

Continuous Groups, Lie Groups, and Lie Algebras

Transcription:

CS 4204 Computer Graphics 2D and 3D Transformations Doug Bowman Adapted from notes by Yong Cao Virginia Tech 1

Transformations What are they? changing something to something else via rules mathematics: mapping between values in a range set and domain set (function/relation) geometric: translate, rotate, scale, shear, Why are they important to graphics? moving objects on screen / in space specifying the camera s s view of a 3D scene mapping from model space to world space to camera space to screen space specifying parent/child relationships 2

Translation Moving an object is called a translation. We translate a point by adding to the x and y coordinates, respectively, the amount the point should be shifted in the x and y directions. We translate an object by translating each vertex in the object. t y t x x new = x old + t x ; y new = y old + t y 3

Scaling Changing the size of an object is called a scale. We scale an object by scaling the x and y coordinates of each vertex in the object. h old h new w old w new s x =w new /w old x new = s x x old s y =h new /h old y new = s y y old 4

Rotation about the origin Consider rotation about the origin by Θ degrees radius stays the same, angle increases by Θ x' = r cos (φ + θ) y' = r sin (φ + θ) x = r cos φ y = r sin φ 5

Rotation about the origin (cont.) From the double angle formulas: sin (A + B) = sinacosb + cosasinb cos (A+B ) = cosacosb - sinasinb Thus, x' = x cos θ y sin θ y' = x sin θ + y cos θ 6

Transformations as matrices Scale: x new = s x x old y new = s y y old Rotation: x 2 = x 1 cosθ - y 1 sin θ y 2 = x 1 sin θ + y 1 cos θ Translation: x new = x old + t x y new = y old + t y 7

Homogeneous Coordinates In order to represent a translation as a matrix multiplication operation we use 3 x 3 matrices and pad our points to become 3 x 1 matrices. This coordinate system (using three values to represent a 2D point) is called homogeneous coordinates. 8

Composite Transformations Suppose we wished to perform multiple transformations on a point: Remember: Matrix multiplication is associative, not commutative! Transform matrices must be pre-multiplied The first transformation you want to perform will be at the far right, just before the point 9

Composite Transformations - Scaling Given our three basic transformations we can create other transformations. A problem with the scale transformation is that it also moves the object being scaled. Scale a line between (2, 1) (4,1) to twice its length. Before After 0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10 10

Composite Transforms - Scaling (cont.) If we scale a line between (0,0) & (2,0) to twice its length, the left-hand endpoint does not move. Before After 0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10 (0,0) is known as a fixed point for the basic scaling transformation. We can use composite transformations to create a scale transformation with different fixed points. 11

Fixed Point Scaling Scale by 2 with fixed point = (2,1) Translate the point (2,1) to the origin Scale by 2 Translate origin to point (2,1) Before 0 1 2 3 4 5 6 7 8 9 10 After 0 1 2 3 4 5 6 7 8 9 10 12

Example of 2D transformation Rotate around an arbitrary point A: y P A x 13

Rotate around an arbitrary point y P A -90 P x 14

Rotate around an arbitrary point We know how to rotate around the origin y P A x 15

Rotate around an arbitrary point but that is not what we want to do! P y A -90 P x P 16

So what do we do? y P A x 17

Transform it to a known case Translate(-A x,-a y ) y P A P A x 18

Second step: Rotation y P Translate(-A x,-a y ) Rotate(-90) A P A P x 19

Final: Put everything back Translate(-A x,-a y ) y A P Rotate(-90) Translate(A x,a y ) P P A P x 20

Rotation about arbitrary point IMPORTANT!: Order M = T(A x,a y ) R(-90) T(-A x,-a y ) y A P P P A P x 21

Rotation about arbitrary point Rotation Of θ Degrees About Point (x,y) Translate (x,y) to origin Rotate Translate origin to (x,y) (x,y) (x,y) 22

Shears Original Data y Shear x Shear 23

Reflections Reflection about the y-axis Reflection about the x-axis 24

More Reflections Reflection about the origin Reflection about the line y=x? 25

Affine Transformations in 3D General form 26

Elementary 3D Affine Transformations Translation 27

Scaling Around the Origin 28

Shear around the origin Along x-axis 29

3D Rotation Various representations Decomposition into axis rotations (x-roll( x-roll, y-roll, z-roll) CCW positive assumption 30

Reminder: 2D rotation (z-roll) 31

Three axes to rotate around Z Y X 32

Z-roll 33

X-roll Cyclic indexing 34

Y-roll 35

Rigid body transformations Translations and rotations Preserve lines, angles and distances 36

Inversion of transformations Translation: T -1 (a,b,c) = T(-a,-b -b,-c) Rotation: R -1 (b) = R axis -1 axis(b) = -b) axis {-b Scaling: S -1 (sx,sy,sz)) = S(1/sx,1/sy,1/sz) Shearing: Sh -1 (a) = Sh(-a) 37

Rotation around an arbitrary axis Euler s s theorem: Any rotation or sequence of rotations around a point is equivalent to a single rotation around an axis that passes through the point. What does the matrix look like? 38

Rotation around an arbitrary axis Axis: u Point: P Angle: β Method: 1. Two rotations to align u with x-axis 2. Do x-roll by β 3. Undo the alignment 39

Derivation 1. R z (-φ)r y (θ) 2. R x (β) 3. R y (-θ)r z (φ) Altogether: R y (-θ)r z (φ)) R x (β) R z (-φ)r y (θ) We can add translation too if the axis is not through the origin 40

Properties of affine transformations Preservation of affine combinations of points. Preservation of lines and planes. Preservation of parallelism of lines and planes. Relative ratios are preserved Affine transformations are composed of elementary ones. 41

General form Rotation, Scaling, Shear Translation 42

Transformations as a change in coordinate system All transformations we have looked at involve transforming points in a fixed coordinate system (CS). Can also think of them as a transformation of the CS itself 43

Transforming the CS - examples Translate(4,4) Rotate(180 ) 44

Why transform the CS? Objects often defined in a natural or convenient CS (2,2) To draw objects transformed by T, we could: Transform each vertex by T, then draw Or, draw vertices in a transformed CS 45

Drawing in transformed CS Tell system once how to draw the object, then draw in a transformed CS to transform the object House drawn in a CS that s been translated, rotated, and scaled 46

Mapping between systems Given: The vertices of an object in CS 2 A transformation matrix M that transforms CS 1 to CS 2 What are the coordinates of the object s vertices in CS 1? 47

Mapping example Translate(4,4) P Point P is at (0,0) in the transformed CS (CS 2 ). Where is it in CS 1? Answer: (4,4) *Note: (4,4) = T 4,4 P 48

Mapping rule In general, if CS 1 is transformed by a matrix M to form CS 2, a point P in CS 2 is represented by MP in CS 1 49

Another example P Translate(4,4), then Scale(0.5, 0.5) Where is P in CS 3? (2,2) Where is P in CS 2? S 0.5,0.5 (2,2) = (1,1) Where is P in CS 1? T 4,4 (1,1) = (5,5) *Note: to go directly from CS 3 to CS 1 we can calculate T 4,4 S 0.5,0.5 (2,2) = (5,5) 50

General mapping rule If CS 1 is transformed consecutively by M 1, M 2,, M n to form CS n+1, then a point P in CS n+1 is represented by CS n+1 M 1 M 2 M n P in CS 1. To form the composite transformation between CSs,, you postmultiply each successive transformation matrix. 51

OpenGL Transformations Learn how to carry out transformations in OpenGL Rotation Translation Scaling Introduce OpenGL matrix modes Model-view Projection 52

OpenGL Matrices In OpenGL matrices are part of the state Multiple types Model-View (GL_MODELVIEW( GL_MODELVIEW) Projection (GL_PROJECTION( GL_PROJECTION) Texture (GL_TEXTURE( GL_TEXTURE) ) (ignore for now) Color(GL_COLOR GL_COLOR) ) (ignore for now) Single set of functions for manipulation Select which to manipulated by glmatrixmode(gl_modelview); glmatrixmode(gl_projection); 53

Current Transformation Matrix (CTM) Conceptually there is a 4 x 4 homogeneous coordinate matrix, the current transformation matrix (CTM) that is part of the state and is applied to all vertices that pass down the pipeline The CTM is defined in the user program and loaded into a transformation unit vertices p C CTM p'=cp vertices 54

CTM operations The CTM can be altered either by loading a new CTM or by postmutiplication Load an identity matrix: C I Load an arbitrary matrix: C M Load a translation matrix: C T Load a rotation matrix: C R Load a scaling matrix: C S Postmultiply by an arbitrary matrix: C CM Postmultiply by a translation matrix: C CT Postmultiply by a rotation matrix: C C R Postmultiply by a scaling matrix: C C S 55

Rotation about a Fixed Point Start with identity matrix: C I Move fixed point to origin: C CT Rotate: C CR Move fixed point back: C CT CT -1 Result: C = TR T 1 which is backwards. This result is a consequence of doing postmultiplications. Let s s try again. 56

Reversing the Order We want C = T 1 R T so we must do the operations in the following order C I C CT -1 C CR C CT Each operation corresponds to one function call in the program. Note that the last operation specified is the first executed in the program 57

CTM in OpenGL OpenGL has a model-view and a projection matrix in the pipeline which are concatenated together to form the CTM Can manipulate each by first setting the correct matrix mode 58

Rotation, Translation, Scaling Load an identity matrix: glloadidentity() Multiply on right: glrotatef(theta, vx, vy, vz) theta in degrees, (vx, vy, vz) define axis of rotation gltranslatef(dx, dy, dz) glscalef( sx, sy, sz) Each has a float (f) and double (d) format (glscaled) 59

Example Rotation about z axis by 30 degrees with a fixed point of (1.0, 2.0, 3.0) glmatrixmode(gl_modelview); glloadidentity(); gltranslatef(1.0, 2.0, 3.0); glrotatef(30.0, 0.0, 0.0, 1.0); gltranslatef(-1.0, -2.0, -3.0); Remember that last matrix specified in the program is the first applied 60

Arbitrary Matrices Can load and multiply by matrices defined in the application program glloadmatrixf(m) glmultmatrixf(m) The matrix m is a one dimension array of 16 elements which are the components of the desired 4 x 4 matrix stored by columns In glmultmatrixf, m multiplies the existing matrix on the right 61

Transformations in OpenGL OpenGL makes it easy to do transformations to the CS, not the object Sequence of operations: Set up a routine to draw the object in its base CS Call transformation routines to transform the CS Object drawn in transformed CS 62

OpenGL transformation example drawhouse(){ glbegin(gl_line_loop); glvertex2i(0,0); glvertex2i(0,2);... glend(); } drawtransformedhouse(){ } glmatrixmode(gl_modelview); gltranslatef(4.0, 4.0, 0.0); glscalef(0.5, 0.5, 1.0); drawhouse(); Draws basic house Draws transformed house 63

Matrix Stacks In many situations we want to save transformation matrices for use later Traversing hierarchical data structures Avoiding state changes when executing display lists OpenGL maintains stacks for each type of matrix Access present type (as set by glmatrixmode) by glpushmatrix() glpopmatrix() 64

OpenGL matrix stack example M 0 glloadmatrixf(m0); glpushmatrix(); glmultmatrixf(m1); glpushmatrix(); glmultmatrixf(m4); render chair2; glpopmatrix(); glpushmatrix(); glmultmatrixf(m3); render chair1; glpopmatrix(); render table; glpopmatrix(); glpushmatrix(); glmultmatrixf(m2); render rug; glpopmatrix() render room; M 1 room M 2 table rug M 3 M 4 chair1 chair2 M 0 *M 1 *M 4 M 0 *M 1 M 0 65