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

Slides:



Advertisements
Similar presentations
3D Transformations Assist. Prof. Dr. Ahmet Sayar
Advertisements

Computer Graphics: 3D Transformations
Computer Graphics Lecture 4 Geometry & Transformations.
Three Dimensional Modeling Transformations
Shivkumar Kalyanaraman Rensselaer Polytechnic Institute 1 : “shiv rpi” Linear Algebra A gentle introduction Linear Algebra has become as basic and as applicable.
Chapter 4.1 Mathematical Concepts
CS 325 Introduction to Computer Graphics 02 / 24 / 2010 Instructor: Michael Eckmann.
CS 376 Introduction to Computer Graphics 02 / 09 / 2007 Instructor: Michael Eckmann.
Chapter 4.1 Mathematical Concepts. 2 Applied Trigonometry Trigonometric functions Defined using right triangle  x y h.
3D Coordinate Systems and Transformations Revision 1
CSCE 590E Spring 2007 Basic Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
3-D Geometry.
Computer Graphics CSC 630 Lecture 2- Linear Algebra.
CS 376 Introduction to Computer Graphics 02 / 26 / 2007 Instructor: Michael Eckmann.
©College of Computer and Information Science, Northeastern UniversityJune 26, CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 11.
CS 376b Introduction to Computer Vision 03 / 04 / 2008 Instructor: Michael Eckmann.
CS 376b Introduction to Computer Vision 03 / 04 / 2008 Instructor: Michael Eckmann.
Computer Graphics with OpenGL 3e
CS 4731: Computer Graphics Lecture 8: 3D Affine transforms Emmanuel Agu.
Linear Algebra Review CSE169: Computer Animation Instructor: Steve Rotenberg UCSD, Winter 2005.
CS 450: Computer Graphics 2D TRANSFORMATIONS
04 – Geometric Transformations Overview Geometric Primitives –Points, Lines, Planes 2D Geometric Transformations –Translation, Rotation, Scaling, Affine,
Mathematical Fundamentals
CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.
COS 397 Computer Graphics Svetla Boytcheva AUBG, Spring 2013.
Transformations Aaron Bloomfield CS 445: Introduction to Graphics
Chapter 4.1 Mathematical Concepts
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
Mathematical Foundations Sections A-1 to A-5 Some of the material in these slides may have been adapted from university of Virginia, MIT and Åbo Akademi.
Dx = 2 dy = 3 Y X D Translation A translation is applied to an object by repositioning it along a straight-line path.
CSE 681 Review: Transformations. CSE 681 Transformations Modeling transformations build complex models by positioning (transforming) simple components.
Transformations Jehee Lee Seoul National University.
CS 325 Introduction to Computer Graphics 02 / 17 / 2010 Instructor: Michael Eckmann.
©Larry F. Hodges (modified by Amos Johnson) 1 3-D Mathematical Preliminaries & Transformations.
Transformations of Objects – 3D
Computer Graphics 2D Transformations. 2 of 74 Contents In today’s lecture we’ll cover the following: –Why transformations –Transformations Translation.
16/5/ :47 UML Computer Graphics Conceptual Model Application Model Application Program Graphics System Output Devices Input Devices API Function.
CS 376 Introduction to Computer Graphics 02 / 23 / 2007 Instructor: Michael Eckmann.
Background Mathematics Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006.
CS 325 Introduction to Computer Graphics 02 / 22 / 2010 Instructor: Michael Eckmann.
CS 325 Introduction to Computer Graphics 02 / 26 / 2010 Instructor: Michael Eckmann.
Geometric Transformations
CS 376 Introduction to Computer Graphics 04 / 25 / 2007 Instructor: Michael Eckmann.
3D Transformation A 3D point (x,y,z) – x,y, and z coordinates
Geometric Transformations UBI 516 Advanced Computer Graphics Aydın Öztürk
January 19, y X Z Translations Objects are usually defined relative to their own coordinate system. We can translate points in space to new positions.
CSCI 425/ D Mathematical Preliminaries. CSCI 425/525 2 Coordinate Systems Z X Y Y X Z Right-handed coordinate system Left-handed coordinate system.
Affine Geometry.
CSCE 552 Fall 2012 Math By Jijun Tang. Applied Trigonometry Trigonometric functions  Defined using right triangle  x y h.
CS 376 Introduction to Computer Graphics 02 / 21 / 2007 Instructor: Michael Eckmann.
Jinxiang Chai CSCE441: Computer Graphics 3D Transformations 0.
1 Teaching Innovation - Entrepreneurial - Global The Centre for Technology enabled Teaching & Learning, N Y S S, India DTEL DTEL (Department for Technology.
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.
Computer Graphics Lecture 11 2D Transformations I Taqdees A. Siddiqi
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
3D Ojbects: Transformations and Modeling. Matrix Operations Matrices have dimensions: Vectors can be thought of as matrices: v=[2,3,4,1] is a 1x4 matrix.
Forward Projection Pipeline and Transformations CENG 477 Introduction to Computer Graphics.
Math Fundamentals Maths revisit.
3. Transformation
Computer Graphics CC416 Week 15 3D Graphics.
Review: Transformations
Review: Transformations
Math 200 Week 3 - Monday Planes.
Lecture 03: Linear Algebra
COMP 175: Computer Graphics February 9, 2016
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Transformations.
Linear Algebra A gentle introduction
Presentation transcript:

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

Michael Eckmann - Skidmore College - CS Spring 2007 Today’s Topics Questions? 3d –3 dimensional vectors –dot product –cross product –parametric equation of a line in 3 dimensions –equation of a plane in 3 dimensions and its derivation –3d primitive transform matrices translation scaling rotation about each coordinate axis –Inverses –homogeneous coordinates reminder –rotation about an arbitrary axis –fixed point scaling

Michael Eckmann - Skidmore College - CS Spring 2007 vectors A vector is a directed line segment that has magnitude (length) and direction. We can define a vector as the difference between two points. (Example on board.) In 2 dimensions: V = P 2 -P 1 = (v x, v y ) In 3 dimensions: V = P 2 -P 1 = (v x, v y, v z ) The v x, v y, and v z values are the projections of the line segment onto the x, y and z axes, respectively. Magnitude of a Vector is determined by the Pythagorean theorem: For 2d: |V| = sqrt(v x 2 + v y 2 ) and for 3d: |V| = sqrt(v x 2 + v y 2 + v z 2 )

Michael Eckmann - Skidmore College - CS Spring 2007 vectors Vector addition: V 1 + V 2 = (v 1x +v 2x, v 1y +v 2y, v 1z +v 2z ) Scalar multiplication: sV = (sv x, sv y, sv z ) Dot product (aka scalar product) of 2 vectors results in a scalar: V 1 ● V 2 = |V 1 | |V 2 |cos θ θ is the (smaller) angle between the two vectors alternatively: V 1 ● V 2 = v 1x v 2x +v 1y v 2y +v 1z v 2z

Michael Eckmann - Skidmore College - CS Spring 2007 vectors Cross product (aka vector product) of 2 vectors results in a vector: V 1 x V 2 = u |V 1 | |V 2 |sin θ θ is the angle between the two vectors u is a unit vector (length = 1) perpendicular to both V 1 and V 2 u's direction is determined by the right-hand rule Right-hand rule is: with your right hand, grasp the axis perpendicular to the plane of the two vectors and make sure that the direction of your fingers curve from v1 to v2. u's direction is the direction of your thumb. Alternatively: V 1 x V 2 = (v 1y v 2z – v 1z v 2y, v 1z v 2x – v 1x v 2z, v 1x v 2y – v 1y v 2x ) Cross product is not commutative, nor associative. V 1 x V 2 = - (V 2 x V 1 )

Michael Eckmann - Skidmore College - CS Spring 2007 vectors Cross product of two vectors is a vector that is perpendicular to the two vectors and has magnitude equal to the area of the parallelogram formed by the two vectors. (picture on board)

Michael Eckmann - Skidmore College - CS Spring 2007 vectors Recap –a vector has magnitude and direction (but no position) –addition of 2 vectors results in a vector –a scalar times a vector results in a vector –Cross product of two vectors results in a vector –but –dot product of two vectors results in a scalar

Michael Eckmann - Skidmore College - CS Spring 2007 lines Parametric equation of a line in 3 dimensions –Given points P 1 and P 2 the equation of a line that contains these points is: x = x 1 + t(x 2 – x 1 ) y = y 1 + t(y 2 – y 1 ) z = z 1 + t(z 2 – z 1 ) –Given a point P 1 and vector V the equation of a line that contains the point and is in the direction of V is: x = x 1 + t(x v ) y = y 1 + t(y v ) z = z 1 + t(z v ) Line = P 1 + t (P 2 – P 1 ) Line = P 1 + Vt

Michael Eckmann - Skidmore College - CS Spring 2007 Planes (part of sec. 3.15) The general plane equation: Ax + By + Cz + D = 0 A, B, C, D are constants and (x,y,z) are the coordinates of the points on the plane. A useful form of the plane equation is: A'x + B'y + C'z + D' = 0 where A'=A/d, B'=B/d, C'=C/d, D'=D/d, and d = sqrt(A 2 + B 2 + C 2 ) Because then it's easy to find the distance between a point (x 1, y 1, z 1 ) and the plane which is simply: A'x 1 + B'y 1 + C'z 1 + D' A normal vector to a plane is perpendicular to the plane. If the equation of the plane is Ax + By + Cz + D = 0, then a normal to the plane is the vector (A, B, C) Pictures on board.

Michael Eckmann - Skidmore College - CS Spring 2007 The plane equation From the drawing on the board –Equation of the plane: Ax + By + Cz + D = 0 –Given three non collinear points, P 1, P 2, P 3 these points uniquely determine the plane –The cross product of P 1 - P 2 and P 3 - P 2, gives us a normal vector N. –For an arbitrary point P = (x, y, z), P is on the plane if N ● [ P - P 2 ] = 0 –Why?

Michael Eckmann - Skidmore College - CS Spring 2007 The plane equation From the drawing on the board –Equation of the plane: Ax + By + Cz + D = 0 –Given three non collinear points, P 1, P 2, P 3 these points uniquely determine the plane –The cross product of P 1 - P 2 and P 3 - P 2, gives us a normal vector N. –For an arbitrary point P = (x, y, z), P is on the plane if N ● [ P - P 2 ] = 0 –Why? Because if N is normal to the plane, and P-P 2 is a vector on the plane, then the angle between these is 90 degrees and so the dot product will be 0, since cos(90) = 0. –If P is not on the plane, therefore P-P 2 is not on the plane, so what happens?

Michael Eckmann - Skidmore College - CS Spring 2007 The plane equation For an arbitrary point P = (x, y, z), P is on the plane if N ● [ P - P 2 ] = 0 –So, we can derive the plane equation like so: –N = (A, B, C) and is normal to the plane –P = (x, y, z) and represents any point on the plane –P 2 = (x 2, y 2, z 2 ) is some fixed point on the plane N ● [ P - P 2 ] = [A,B,C] ● [x- x 2,y-y 2, z- z 2 ]= A(x- x 2 ) + B(y-y 2 ) + C(z- z 2 ) = Ax + By + C z + A(- x 2 ) + B(-y 2 ) + C(- z 2 ) = 0 Notice that x, y and z are variables and the rest are constant values so this gives Ax + By + C z + D = 0 where D = A(- x 2 ) + B(-y 2 ) + C(- z 2 )

Michael Eckmann - Skidmore College - CS Spring 2007 Inverse Transforms and Identity The inverse of a Matrix is the matrix that when multiplied by the original results in the Identity matrix. The identity matrix is an nxn matrix with 1's along the main diagonal (from upperleft to lowerright) and 0's elsewhere. MM -1 = I = M -1 M

Michael Eckmann - Skidmore College - CS Spring 2007 Reminder about Homogeneous Coordinates When we transform some homogeneous point (x,y,z,1) we may end up with something other than 1 in the homogeneous parameter slot i.e. (x 1,y 1,z 1,w), w!= 1. To figure out which point to plot in 3d, we need to divide each coordinate by w x' = x 1 / w y' = y 1 / w z' = z 1 / w 1 = w / w so we plot (x',y',z')

Michael Eckmann - Skidmore College - CS Spring d transformations Translation Scale Rotation Shear

Michael Eckmann - Skidmore College - CS Spring d Translation 3d Translation in homogeneous coordinates is a direct extension of translation in 2d. [ t x ] [x] [x+t x ] [ t y ] [y] = [y+t y ] [ t z ] [z] [z+t z ] [ ] [1] [ 1 ]

Michael Eckmann - Skidmore College - CS Spring d Scale [ s x ] [x] [s x x] [ 0 s y 0 0 ] [y] = [s y y] [ 0 0 s z 0 ] [z] [s z z] [ ] [1] [ 1 ] 3d Scale has the same problem/feature that 2d scaling has, namely it also translates.

Michael Eckmann - Skidmore College - CS Spring d Rotation Positive rotations are defined to be Rotation about the x-axis is positive going from y to z Rotation about the y-axis is positive going from z to x Rotation about the z-axis is positive going from x to y (see figures 5-36 and 5-38 in text.)

Michael Eckmann - Skidmore College - CS Spring 2007 Right-handed 3d coordinate system

Michael Eckmann - Skidmore College - CS Spring d Rotation About z-axis [ cos θ -sin θ 0 0 ] [ sin θ cos θ 0 0 ] [ ] [ ] About x-axis [ ] [ 0 cos θ -sin θ 0 ] [ 0 sin θ cos θ 0 ] [ ] About y-axis [ cos θ 0 sin θ 0 ] [ ] [ -sin θ 0 cos θ 0 ] [ ] Let's, as an example rotate the point (4,6,0) (in homogeneous it is (4,6,0,1)) about x-axis, positive 60 degrees.

Michael Eckmann - Skidmore College - CS Spring 2007 xy Shear [ 1 0 sh x 0 ] [x] [x+sh x z] [ 0 1 sh y 0 ] [y] = [y+sh y z] [ ] [z] [ z ] [ ] [1] [ 1 ] Let's transform a unit cube with this shear and set sh x = 1 and sh y = 2 points are: (0,0,0), (0,0,1), (0,1,0), (1,0,0), (0,1,1), (1,0,1), (1,1,0), (1,1,1)

Michael Eckmann - Skidmore College - CS Spring 2007 xy Shear [ 1 0 sh x 0 ] [x] [x+sh x z] [ 0 1 sh y 0 ] [y] = [y+sh y z] [ ] [z] [ z ] [ ] [1] [ 1 ] Let's transform a unit cube with this shear and set sh x = 1 and sh y = 2 points are: (0,0,0), (0,0,1), (0,1,0), (1,0,0), (0,1,1), (1,0,1), (1,1,0), (1,1,1) transformed they are: (0,0,0), (1,2,1), (0,1,0), (1,0,0), (1,3,1), (2,2,1), (1,1,0), (2,3,1)

Michael Eckmann - Skidmore College - CS Spring 2007 Rotation of θ about an arbitrary axis To rotate about an arbitrary axis: The axis can be specified by two points on it, P 1 and P 2 The vector P 2 - P 1 is on this axis. Before anything else, we should translate P 1 to the origin. If P 1 = (x 1,y 1,z 1 ) then T = [ x 1 ] [ y 1 ] [ z 1 ] [ ]

Michael Eckmann - Skidmore College - CS Spring 2007 What we want to do next is to rotate the axis so that it is on the z-axis. Then rotate by an angle of  about the z axis. Then we need to do the inverses of the transforms in reverse order. That is, rotate back from z-axis to original angle. Then translate back from origin to P 1. Does that make sense? Rotation of θ about an arbitrary axis

Michael Eckmann - Skidmore College - CS Spring 2007 We know how to rotate about the x-axis, y-axis and z-axis. We also know how to translate. Therefore we will use a composition of these primitive transforms to get the rotation about an arbitrary axis. Rotation of θ about an arbitrary axis

Michael Eckmann - Skidmore College - CS Spring 2007 What we want to do now is to rotate the axis so that it is on the z-axis. To rotate the axis from where it is now to the z- axis we can do this in two steps (rotate about 2 different coordinate axes). One way to do this is: –a) rotate the axis so that it is on the y-z plane What axis will we rotate about, to get it on y-z plane? –b) rotate the axis so that it is on the z-axis Once we have it on the y-z plane, what axis will we rotate about to get it on z-axis? Rotation of θ about an arbitrary axis

Michael Eckmann - Skidmore College - CS Spring 2007 What we want to do now is to rotate the axis so that it is on the z-axis. To rotate the axis from where it is now to the z- axis we can do this in two steps –a) rotate the axis so that it is on the y-z plane Rotate about y-axis to get it on y-z plane. –b) rotate the axis so that it is on the z-axis Rotate about x-axis to get it on z-axis. Rotation of θ about an arbitrary axis

a) rotate the axis so that it is on the y-z plane Rotate about y-axis to get it on y-z plane. See handout diagram. U = (u 1,u 2,u 3 ) We need to find angle β, the triangle with side lengths u 3 u 1 and a is a right triangle: cos β = u 3 / a sin β = u 1 / a a = sqrt(u u 3 2 ) Rotating U towards y-z is a negative angle, so the matrix is R y (- β ) Rotation of θ about an arbitrary axis

b) rotate the axis so that it is on the z-axis Rotate about x-axis to get it on z-axis. See second handout diagram. This is the y-z plane It may not be immediately obvious, but the length a, on this diagram is the same as from the previous. U = (u 1,u 2,u 3 ) We need to find angle μ, the triangle with side lengths u 2 a and |U| is a right triangle: cos μ = a / |U| sin μ = u 2 / |U| a = sqrt(u u 3 2 ) This rotation is in a positive direction, so the matrix is R x ( μ ) Rotation of θ about an arbitrary axis

The remaining steps are: Rotate by an angle of θ about the z axis, which is simply R z ( θ ) Then we need to do the inverses of the transforms in reverse order. That is, rotate back from z-axis to original angle. Then translate back from origin to P 1. R x (- μ ) R y ( β ) T -1 Rotation of θ about an arbitrary axis

To rotate an angle of θ about an arbitrary axis the composite transform is: T -1 R y ( β ) R x (- μ ) R z ( θ ) R x ( μ ) R y (- β ) T Notice that we are multiplying this matrix by a point and the point goes on the right. Therefore, it acts like the first transform applied to the point is T, then R y (- β ), then the rest from right to left. Rotation of θ about an arbitrary axis

Michael Eckmann - Skidmore College - CS Spring d Scale w/ fixed point First transform the fixed point to the origin with a translation matrix. Then do the 3d Scale [ s x ] [ 0 s y 0 0 ] [ 0 0 s z 0 ] [ ] Then transform the origin back to the fixed point via the inverse of the first translation matrix.

Michael Eckmann - Skidmore College - CS Spring 2007 Rigid body vs. Affine Transformations that preserve line lengths and angles do not deform shapes. Therefore they are called rigid body transformations. –Translation and Rotation (and any combination of these) are examples of rigid body transformations. Transformations that preserve parallel lines, that is, lines that were parallel before the transform remain parallel after the transform are called affine transformations. –Line lengths and angles need not be preserved for a transformation to be considered affine –Rotation, Translation, Scale and Shear (and any combination of these) are examples of affine transformations.