CS 376 Introduction to Computer Graphics 02 / 09 / 2007 Instructor: Michael Eckmann.

Slides:



Advertisements
Similar presentations
CS 376 Introduction to Computer Graphics 02 / 02 / 2007 Instructor: Michael Eckmann.
Advertisements

COMPUTER GRAPHICS 2D TRANSFORMATIONS.
Transformations We want to be able to make changes to the image larger/smaller rotate move This can be efficiently achieved through mathematical operations.
Three Dimensional Modeling Transformations
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
1 Computer Graphics Chapter 6 2D Transformations.
CS 376 Introduction to Computer Graphics 02 / 07 / 2007 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 02 / 24 / 2010 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 02 / 26 / 2007 Instructor: Michael Eckmann.
Transformations CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Computer Graphics with OpenGL 3e
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 2D TRANSFORMATIONS
By: Suhas Navada and Antony Jacob
Unit 9: Vectors, Matrices and Transformations
Mathematical Fundamentals
CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.
2.2 Linear Transformations in Geometry For an animation of this topic visit
5.2 Three-Dimensional Geometric and Modeling Transformations 2D3D Consideration for the z coordinate.
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
CS 376 Introduction to Computer Graphics 04 / 23 / 2007 Instructor: Michael Eckmann.
CS 480/680 Computer Graphics Transformations Dr. Frederick C Harris, Jr.
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 03 / 08 / 2010 Instructor: Michael Eckmann.
2D Transformation of Graphics
Lecture Notes: Computer Graphics.
Part7: Geometric Transformations
Transformations Jehee Lee Seoul National University.
CS 325 Introduction to Computer Graphics 02 / 17 / 2010 Instructor: Michael Eckmann.
Geometric Transformations
CS 376 Introduction to Computer Graphics 02 / 16 / 2007 Instructor: Michael Eckmann.
Computer Graphics 2D Transformations. 2 of 74 Contents In today’s lecture we’ll cover the following: –Why transformations –Transformations Translation.
CS 376 Introduction to Computer Graphics 02 / 23 / 2007 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 02 / 22 / 2010 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 02 / 26 / 2010 Instructor: Michael Eckmann.
CS 376b Introduction to Computer Vision 04 / 28 / 2008 Instructor: Michael Eckmann.
Computer Graphics 3D Transformations. Translation.
Two-Dimensional Geometric Transformations ch5. 참조 Subjects : Basic Transformations Homogeneous Coordinates Composite Transformations Other Transformations.
Geometric Transformations
4-4 Geometric Transformations with Matrices Objectives: to represent translations and dilations w/ matrices : to represent reflections and rotations with.
Transformations of Geometric Figures Dr. Shildneck Fall, 2015.
Objective: Students will be able to represent translations, dilations, reflections and rotations with matrices.
CS 376 Introduction to Computer Graphics 04 / 25 / 2007 Instructor: Michael Eckmann.
Transformations CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
Geometric Transformations UBI 516 Advanced Computer Graphics Aydın Öztürk
3-D Geometric Transformations
3D Geometric Transformation
II-1 Transformations Transformations are needed to: –Position objects defined relative to the origin –Build scenes based on hierarchies –Project objects.
Learning Objectives Affine transformations Affine transformations Translation Translation Rotation Rotation Scaling Scaling Reflection Reflection Shear.
 An image is the new figure, and the preimage is the original figure  Transformations-move or change a figure in some way to produce an image.
III- 1 III 3D Transformation Homogeneous Coordinates The three dimensional point (x, y, z) is represented by the homogeneous coordinate (x, y, z, 1) In.
CS 376 Introduction to Computer Graphics 02 / 21 / 2007 Instructor: Michael Eckmann.
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.
Chapter 9 Properties of Transformations Warren Luo Matthew Yom.
CS 376 Introduction to Computer Graphics 02 / 14 / 2007 Instructor: Michael Eckmann.
CS 551 / 645: Introductory Computer Graphics Viewing Transforms.
CS 325 Introduction to Computer Graphics 02 / 19 / 2010 Instructor: Michael Eckmann.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
Computer Graphic 2 D Transformation.
3D Geometry and Transformations
Instructor: Dr. Shereen Aly Taie Basic Two-Dimensional Geometric Transformation 5.2 Matrix Representations and Homogeneous Coordinates 5.3 Inverse.
CPT450 – Computer Graphics
Lecture 10 Geometric Transformations In 3D(Three- Dimensional)
Computer Graphics CC416 Week 15 3D Graphics.
Computer Graphics 3D Transformations
4-4 Geometric Transformations with Matrices
Presentation transcript:

CS 376 Introduction to Computer Graphics 02 / 09 / 2007 Instructor: Michael Eckmann

Michael Eckmann - Skidmore College - CS Spring 2007 Today’s Topics Questions? 2D Transformations –Translation –Scaling –Rotation Homogeneous coordinates Matrices representing the transforms of the homogeneous points Fixed point scaling Fixed point rotation Shearing and reflection

Michael Eckmann - Skidmore College - CS Spring 2007 Geometric Transformations (2D) Reading: (2D geometric transformations) Translations Rotations Scaling Homogeneous Coordinates Shearing Reflections

Michael Eckmann - Skidmore College - CS Spring 2007 Matrices An m by n matrix is a two dimensional array of values with m rows and n columns. Points are typically represented by column matrices (meaning they have multiple rows, but only 1 column) Matrix multiplication (3x3 times a 3x3 yields a 3x3 matrix) ( a b c ) ( j k l ) ( aj+bm+cp ak+bn+cq al+bo+cr ) ( d e f ) ( m n o ) = ( dj+em+fp dk+en+fq dl+eo+fr ) ( g h i ) ( p q r ) ( gj+hm+ip gk+hn+iq gl+ho+ir ) Matrix multiplication (2x2 times a 2x1 yields a 2x1 column matrix) ( a b ) ( x ) = ( ax+by ) ( c d ) ( y ) ( cx+dy ) A 2x2 matrix times a 2x1 matrix (a point) yields another point. Matrix multiplication is associative. ABC = (AB)C = A(BC).

Michael Eckmann - Skidmore College - CS Spring 2007 Translations (2D) Recall the idea that for the circle algorithm that we did computations assuming the circle's center was the origin. Then when we plotted the points we offset the calculated point by the actual center by just adding the respective coordinates. What we did there was perform a translation. Translation is a transformation on an object that simply moves it to a different position somewhere else within the same coordinate system. To translate an object we translate each of its vertices (points). To translate a 2d point (x 1, y 1 ) by t x in the x direction and t y in the y direction, we simply calculate the new coordinates to be: (x 2, y 2 ) = (x 1 + t x, y 1 + t y )

Michael Eckmann - Skidmore College - CS Spring 2007 Scaling (2D) Scaling is a transformation on an object that changes its size. Just as the translation could have been different amounts in x and y, you can scale x and y by different factors. Scaling is a transformation on an object that changes its size within the same coordinate system. To scale an object we scale each of its vertices (points). To scale a 2d point (x 1, y 1 ) by s x in the x direction and s y in the y direction, we simply calculate the new coordinates to be: (x 2, y 2 ) = (s x x 1, s y y 1 )

Michael Eckmann - Skidmore College - CS Spring 2007 Rotation (2D) Rotation is a transformation on an object that changes its position in a specific way (by rotating the object some angle about an axis). Rotations in the x-y plane are about an axis parallel to z. The point of intersection of the rotation axis with the x-y plane is the pivot point. We need to specify the angle and pivot point about which the object is to be rotated. To rotate an object we rotate each of its vertices (points). Positive angles are in the counterclockwise direction.

Michael Eckmann - Skidmore College - CS Spring 2007 Rotation (2D) To rotate a 2d point (x 1, y 1 ) an arbitrary angle of B, about the origin as a pivot point do the following. From the diagram on the board (also see figure 5-4 in the text) we have: sin(A + B) = y 2 / r => y 2 = r sin(A + B) cos(A + B) = x 2 / r x 2 = r cos(A + B) sin(A) = y 1 / r y 1 = r sin(A) cos(A) = x 1 / r x 1 = r cos(A) Known equalities exist for sin(A+B) and cos(A+B) sin(A + B) = sin(A) cos(B) + cos(A) sin(B) cos(A + B) = cos(A) cos(B) – sin(A) sin(B)

Michael Eckmann - Skidmore College - CS Spring 2007 Rotation (2D) Solve for x 2 and y 2. x 2 = r cos(A + B) = r cos(A) cos(B) – r sin(A) sin(B) = x 1 cos(B) – y 1 sin(B) y 2 = r sin(A + B) = r sin(A) cos(B) + r cos(A) sin(B) = y 1 cos(B) + x 1 sin(B) So, (x 2, y 2 ) = (x 1 cos(B) – y 1 sin(B), y 1 cos(B) + x 1 sin(B) ) This will rotate a point (x 1, y 1 ) an angle of B about the pivot point of the origin.

Michael Eckmann - Skidmore College - CS Spring 2007 Transformation Matrices (2D) TRANSLATION: (x 2, y 2 ) = (x 1 + t x, y 1 + t y ) ( x 2 ) = ( x 1 ) + ( t x ) ( y 2 ) ( y 1 ) ( t y ) SCALING: (x 2, y 2 ) = (s x x 1, s y y 1 ) ( x 2 ) = ( s x 0 ) ( x 1 ) ( y 2 ) ( 0 s y ) ( y 1 ) ROTATION: (x 2, y 2 ) = (x 1 cos(B) – y 1 sin(B), y 1 cos(B) + x 1 sin(B) ) ( x 2 ) = ( cos(B) – sin(B) ) ( x 1 ) ( y 2 ) ( sin(B) cos(B) ) ( y 1 )

Michael Eckmann - Skidmore College - CS Spring 2007 Homogeneous Coordinates Translations, Scales and Rotations can be done as described in the previous slides. What was not described was rotation about an arbitrary pivot point. In addition to the matrix multiplication involved, a vector (column matrix) add would need to be added in. So, both translations and rotations have an add of a column matrix. In addition, rotations and scales have matrix multiplications as well. To be able to represent all transformations only with matrix multiplications (without additions of column matrices), we use homogeneous coordinates.

Michael Eckmann - Skidmore College - CS Spring 2007 Homogeneous Coordinates To represent a 2d point in homogeneous coordinates instead of just an x and a y to represent a 2d point, we use an x, a y and an additional value, the homogeneous parameter. (x,y) => (cx, cy, c) where c is the homogeneous parameter. There are an infinite number of equivalent homogeneous representations for each coordinate point (x,y). When c = 1, we have (x,y) => (x, y, 1) Using homogeneous coordinates allows us to represent 2d transformations as matrix multiplications exclusively.

Michael Eckmann - Skidmore College - CS Spring 2007 Homogeneous Coordinates Transformations on homogeneous coordinates TRANSLATION: (x 2, y 2 ) = (x 1 + t x, y 1 + t y ) ( x 2 ) = ( 1 0 t x ) ( x 1 ) ( y 2 ) ( 0 1 t y ) ( y 1 ) ( 1 ) ( ) ( 1 ) SCALING: (x 2, y 2 ) = (s x x 1, s y y 1 ) ( x 2 ) = ( s x 0 0 ) ( x 1 ) ( y 2 ) ( 0 s y 0 ) ( y 1 ) ( 1 ) ( ) ( 1 )

Michael Eckmann - Skidmore College - CS Spring 2007 Homogeneous Coordinates Transformations on homogeneous coordinates ROTATION: (x 2, y 2 ) = (x 1 cos(B) – y 1 sin(B), y 1 cos(B) + x 1 sin(B) ) ( x 2 ) = (cos(B) – sin(B) 0 ) ( x 1 ) ( y 2 ) (sin(B) cos(B) 0 ) ( y 1 ) ( 1 ) ( ) ( 1 ) These three transform matrices are sometimes written as –T(t x,t y ) –S(s x,s y ) –R(B)

Michael Eckmann - Skidmore College - CS Spring 2007 Scaling a line segment Let's look at this example on the board. Example: Scale a line segment from (3,2) to (5,2) by 2 in the x-direction. ( x 0 ) ( ) ( 3 ) ( 6 ) ( y 0 ) = ( ) ( 2 ) = ( 2 ) ( 1 ) ( ) ( 1 ) ( 1 ) And the other endpoint: ( x end ) ( ) ( 5 ) ( 10 ) ( y end ) = ( ) ( 2 ) = ( 2 ) ( 1 ) ( ) ( 1 ) ( 1 ) Problem: The line segment (3,2) to (5,2) when scaled by 2 in x-direction gives a line segment from (6,2) to (10, 2). Yes it's original length in the x-direction was 2 and now it is 4, but the line also was translated. Let's see it on the board.

Michael Eckmann - Skidmore College - CS Spring 2007 Fixed point scaling Specify a point that will remain fixed after the scaling. This is the fixed-point. Let's scale the same line segment but this time fix the left endpoint (3,2). To do this, we need to: –a) first translate (3, 2) to the origin –b) scale by 2 in x-direction (like before) –c) then translate the origin back to (3, 2) This will yield a matrix multiplication M c M b M a = M fps which we will then multiply M fps P, where P is a homogeneous point, to get the transformed point. Notice the order: matrix M a is closest to the point, then M b then M c

Michael Eckmann - Skidmore College - CS Spring 2007 Fixed point scaling a) the matrix to translate (3, 2) to the origin is this: (1 0 -3) (0 1 -2) (0 0 1) b) the matrix to scale by 2 in x direction is this: (2 0 0) (0 1 0) (0 0 1) c) the matrix to translate the origin back to (3, 2) is this: (1 0 3) (0 1 2) (0 0 1)

Michael Eckmann - Skidmore College - CS Spring 2007 Fixed point scaling a) first translate (3, 2) to the origin b) scale by 2 in x-direction (like before) c) then translate the origin back to (3, 2) (1 0 3) (2 0 0) (1 0 -3) ( 2 0 3) ( ) ( ) (0 1 2) (0 1 0) (0 1 -2) = ( 0 1 2) ( ) = (0 1 0 ) (0 0 1) (0 0 1) (0 0 1) ( 0 0 1) ( ) (0 0 1 ) Multiply this matrix by each of the vertices (endpoints of the line segment): ( ) ( 3 ) ( 3 ) (0 1 0 ) ( 2 ) = ( 2 ) (0 0 1 ) ( 1 ) ( 1 ) ( ) ( 5 ) ( 7 ) (0 1 0 ) ( 2 ) = ( 2 ) (0 0 1 ) ( 1 ) ( 1 ) Notice: initial endpoint (the fixed-point) stayed the same after transformation and the new width in x-direction is 4 (which is 2 the scale factor * 2 the original length).

Michael Eckmann - Skidmore College - CS Spring 2007 Fixed point scaling Let's scale the same line segment but this time fix the midpoint (4,2). To do this, we need to: –a) first translate (4, 2) to the origin –b) scale by 2 in x-direction (like before) –c) then translate the origin back to (4, 2)

Michael Eckmann - Skidmore College - CS Spring 2007 Fixed point scaling a) first translate (4, 2) to the origin b) scale by 2 in x-direction (like before) c) then translate the origin back to (4, 2) (1 0 4) (2 0 0) (1 0 -4) ( 2 0 4) ( ) ( ) (0 1 2) (0 1 0) (0 1 -2) = ( 0 1 2) ( ) = (0 1 0 ) (0 0 1) (0 0 1) (0 0 1) ( 0 0 1) ( ) (0 0 1 ) Multiply this matrix by each of the vertices (endpoints of the line segment): ( ) ( 3 ) ( 2 ) (0 1 0 ) ( 2 ) = ( 2 ) (0 0 1 ) ( 1 ) ( 1 ) ( ) ( 5 ) ( 6 ) (0 1 0 ) ( 2 ) = ( 2 ) (0 0 1 ) ( 1 ) ( 1 ) Notice: the line segment stretched equally left and right from the middle. The new width in x-direction is 4 (which is 2 the scale factor * 2 the original length).

Michael Eckmann - Skidmore College - CS Spring 2007 Fixed point rotation To rotate an object some angle B about a fixed point (x p, y p ) we do: –a) first translate (x p, y p ) to the origin –b) rotate by angle B –c) then translate the origin back to (x p, y p ) This will yield a matrix multiplication M c M b M a = M fpr which we will then multiply M fpr P, where P is a homogeneous point, to get the transformed point. (1 0 x p ) (cos(B) – sin(B) 0 ) (1 0 -x p ) ( cos(B) -sin(B) x p ) ( 1 0 -x p ) (0 1 y p ) (sin(B) cos(B) 0 ) (0 1 -y p ) = ( sin(B) cos(B) y p ) ( 0 1 -y p ) (0 0 1 ) (0 0 1) (0 0 1 ) ( ) ( ) ( cos(B) -sin(B) -x p cos(B) + y p sin(B) + x p ) = ( sin(B) cos(B) -x p sin(B) – y p cos(B) + y p ) ( )

Michael Eckmann - Skidmore College - CS Spring 2007 Other transformations Shearing Y shear: (1 0 0) (sh y 1 0) (0 0 1) X shear: (1 sh x 0) (0 1 0) (0 0 1) Examples of what these do on the board.

Michael Eckmann - Skidmore College - CS Spring 2007 Other transformations Reflections About the y-axis: (-1 0 0) (0 1 0) (0 0 1) About the x-axis: (1 0 0) (0 -1 0) (0 0 1) About the z-axis: (-1 0 0) (0 -1 0) (0 0 1) Examples of what these do on the board. About the line y=x: (0 1 0) (1 0 0) (0 0 1) About the line y=-x: (0 -1 0) (-1 0 0) (0 0 1)