COS 397 Computer Graphics Svetla Boytcheva AUBG, Spring 2013
Lecture 2 Ray Tracing & Transformations
9/5/2015 Outline Points and Vectors Matrices Vector Operations Ray Tracing Homogenous coordinates Affine Transformations –Translation –Rotation –Scaling –Projection View Point Coordinates of objects on the surface of other objects
Points and Vectors 9/5/2015
Points and Vectors Drawing systems of particles Determining coordinates of other objects Drawing objects 9/5/2015
Points and Vectors Points –(x,y,z) Representation –Absolute coordinates (point) –Relative coordinate (radius-vector) –Distance (vector) –Direction (vector)
Points in 3D 3D absolute coordinates P(x,y,z) y Z Y X x z
Radius-vector Relative coordinate (radius-vector) (0,0,0) P(x,y,z) y Z Y X x z
Length and Magnitude Calculating the length/magnitude –Requires reference point R |p| x x x x zzzz y y y yR Z Y X
Direction Determines the direction in 3D –This is not sufficient for complete orientation |p| Z Y X
Points and Vectors operations
Vectors representation Vectors (points) Vector defined by points X 1 and X 2
Examples Vector p(5,2,3) Vector q from point (3,0,8) to (0,2,7)
Point Vector: Point position and direction – Magnitude - Direction V P2P2 P1P1 x1x1 x2x2 y1y1 y2y2 Points and Vectors
Length Vector p length Unit vector –Vector with length=1
Examples Vector p(5,2,3) Vector p from (3,0,8) to (0,2,7)
Addition and Subtraction Vector can be added or subtracted only to other vector
Examples Addition of p(5,2,3) and q(-1,-1,1) Subtraction of q(-1,-1,1) and r(4,1,4)
Product Various product operations –Product with scalar (i.e. vector and number) –Scalar product of vectors –Vector product of vectors Three of them are used in Computer Graphics for important operations
Product with scalar Product with number Geometrical meaning –Scaling (extending, shortening) vector –Preserves the direction for k>0 –Reverses direction when k<0 (the opposite direction)
Examples Doubled vector p(5,2,3) Reversed vector q(-1,-1,1)
Unit Vector Unit vector Geometrical meaning –Vector with length = 1 –Preserves the direction –Can be applied only over non-zero vectors
Examples Unit vector of p(5,2,3) Check
Scalar Product Product of two vectors, the result is scalar (number) –Angle between two vectors Geometrical/Graphical meaning –Checking for perpendicularity –Lightening of surface –Calculating the area
exexexex p.q calculating Using unit axis vectors p eyeyeyey ezezezez Z Y X
Multiply Remember that Find
Lucky method –Lying in the same plane –Angle between = 45 о First class method –"First class" in terms of quality – but also because it may be applied by first grader student Examples (2,2,0).(0,1,0)
Example Check whether the vectors are perpendicular –p(4,0,1) and q(-2,3,8) Solution
Scalar Product Definition For Cartesian Reference Frame Properties –Commutative –Distributive |V 2 |cos V2V2 V1V1 Dot Product, Inner Product
Vector product Vector product and the result is vector –Angle between two vectors Geometrical meaning –Finding normal vectors –Parallelogram Area
Where vector points on? The Result vector of Vector product is: –Perpendicular to the plane defined by to vector in this product –Lies in the plane where the direction of rotation from the first to the second vector is positive (i. e. counterclockwise) V1V1 V2V2 V1 V2V1 V2 u
How to remember? Use right hand –Coordinate system PQR is right-hand Снимка: FreeDigitalPhotos.net
Unit Vectors exexexex eyeyeyey ezezezez exexexex eyeyeyey ezezezez Z Y X Z Y X
Calculation of pхq Using unit axis vectors
After vector product of unit vectors Regroup
Final Result
Vector Product Definition For Cartesian Reference Frame Properties –AntiCommutative –Not Associative –Distributive Cross Product, Outer Product V1V1 V2V2 V1 V2V1 V2 u
Examples Scalar ProductVector Product Normal Vector of the Plane V2V2 V1V1 Angle between Two Edges (x2,y2)(x2,y2) (x0,y0)(x0,y0) (x1,y1)(x1,y1)
Determinant of Matrix Definition –For a square matrix, combining the matrix elements to product a single number 2 2 matrix Determinant of n n Matrix A (n 2)
Inverse Matrix Definition –Non-singular matrix If and only if the determinant of the matrix is non-zero 2 2 matrix Properties
2D Geometric Transformations
Geometric Transformation Definition –Translation, Rotation, Scaling Motivation – Why do we need geometric transformations in CG? –As a viewing aid –As a modeling tool –As an image manipulation tool
Example: 2D Geometric Transformation Modeling Coordinates World Coordinates
Example: 2D Scaling Modeling Coordinates World Coordinates Scale(0.3, 0.3)
Example: 2D Rotation Modeling Coordinates Scale(0.3, 0.3) Rotate(-90) World Coordinates
Example: 2D Translation Modeling Coordinates Scale(0.3, 0.3) Rotate(-90) Translate(5, 3) World Coordinates
Example: 2D Geometric Transformation Modeling Coordinates World Coordinates Again?
Example: 2D Geometric Transformation Modeling Coordinates World Coordinates Scale Translate Scale Rotate Translate
Basic 2D Transformations Translation – Scale – Rotation – Shear –
Basic 2D Transformations Translation – Scale – Rotation – Shear – Transformations can be combined (with simple algebra)
Basic 2D Transformations Translation – Scale – Rotation – Shear –
Basic 2D Transformations Translation – Scale – Rotation – Shear –
Basic 2D Transformations Translation – Scale – Rotation – Shear –
Basic 2D Transformations Translation – Scale – Rotation – Shear –
Matrix Representation Represent a 2D Transformation by a Matrix Apply the Transformation to a Point Transformation Matrix Point
Matrix Representation Transformations can be combined by matrix multiplication Matrices are a convenient and efficient way to represent a sequence of transformations Transformation Matrix
2×2 Matrices What types of transformations can be represented with a 2×2 matrix? 2D Identity 2D Scaling
2×2 Matrices What types of transformations can be represented with a 2×2 matrix? 2D Rotation 2D Shearing
2×2 Matrices What types of transformations can be represented with a 2×2 matrix? 2D Mirror over Y axis 2D Mirror over (0,0)
2×2 Matrices What types of transformations can be represented with a 2×2 matrix? 2D Translation NO!! Only linear 2D transformations can be Represented with 2x2 matrix
2D Translation 2D translation can be represented by a 3×3 matrix –Point represented with homogeneous coordinates
Basic 2D Transformations Basic 2D transformations as 3x3 Matrices Translate Shear Scale Rotate
Homogeneous Coordinates Add a 3rd coordinate to every 2D point –(x, y, w) represents a point at location (x/w, y/w) –(x, y, 0) represents a point at infinity –(0, 0, 0) Is not allowed x y (2, 1, 1) or (4, 2, 2) or (6, 3, 3) Convenient Coordinate System to Represent Many Useful Transformations
Linear Transformations Linear transformations are combinations of … –Scale –Rotation –Shear, and –Mirror Properties of linear transformations –Satisfies: –Origin maps to origin –Lines map to lines –Parallel lines remain parallel –Ratios are preserved –Closed under composition
Affine Transformations Affine transformations are combinations of –Linear transformations, and –Translations Properties of affine transformations –Origin does not map to origin –Lines map to lines –Parallel lines remain parallel –Ratios are preserved –Closed under composition
Projective Transformations Projective transformations… –Affine transformations, and –Projective warps Properties of projective transformations –Origin does not map to origin –Lines map to lines –Parallel lines do not necessarily remain parallel –Ratios are not preserved –Closed under composition
Matrix Composition Transformations can be combined by matrix multiplication Efficiency with premultiplication –Matrix multiplication is associative
Matrix Composition Rotate by around arbitrary point (a,b) – Scale by sx, sy around arbitrary point (a,b) – (a,b)
Pivot-Point Rotation TranslateRotateTranslate (x r,y r )
General Fixed-Point Scaling TranslateScaleTranslate (x f,y f )
Shear Converted to a parallelogram x’ = x + sh x · y, y’ = y Transformed to a shifted parallelogram (Y = Yref) x’ = x + sh x · ( y-y ref ), y’ = y (Sh x =2) (Sh x =1/2, y ref =-1) x y x y x y x y (0,0)(1,0) (1,1) (0,1) ( 0,0 )( 1,0 ) ( 1,1 ) (0,1) (0,0)(1,0) (3,1)(2,1) ( 1/2,0 ) ( 3/2,0 ) ( 2,1 ) ( 1,1 ) (0,-1)
Shear Transformed to a shifted parallelogram (X = Xref) x’ = x, y’ = sh y · ( x-x ref ) + y (Sh y =1/2, x ref =-1) x y x y (-1,0) ( 0,0 )( 1,0 ) ( 1,1 ) ( 0,1 ) ( 0,1/2 )( 1,1 ) ( 1,2 ) ( 0,3/2 )
3D Geometric Transformation
Contents Translation Scaling Rotation Rotations with Quaternions Other Transformations Coordinate Transformations
Transformation in 3D Transformation Matrix 3 3 : Scaling, Reflection, Shearing, Rotation 3 1 : Translation 1 3 : Homogeneous representation 1 1 : Uniform global Scaling
3D Translation Translation of a Point x z y
3D Scaling Uniform Scaling x z y
Relative Scaling Scaling with a Selected Fixed Position xxx x z z zz y yy y Original positionTranslateScaling Inverse Translate
3D Rotation Coordinate-Axes Rotations –X-axis rotation –Y-axis rotation –Z-axis rotation General 3D Rotations –Rotation about an axis that is parallel to one of the coordinate axes –Rotation about an arbitrary axis
Coordinate-Axes Rotations Z-Axis Rotation X-Axis Rotation Y-Axis Rotation z y x z y x z y x
Order of Rotations Order of Rotation Affects Final Position –X-axis Z-axis –Z-axis X-axis
General 3D Rotations Rotation about an Axis that is Parallel to One of the Coordinate Axes –Translate the object so that the rotation axis coincides with the parallel coordinate axis –Perform the specified rotation about that axis –Translate the object so that the rotation axis is moved back to its original position
General 3D Rotations Rotation about an Arbitrary Axis Basic Idea 1.Translate (x1, y1, z1) to the origin 2.Rotate (x’2, y’2, z’2) on to the z axis 3.Rotate the object around the z-axis 4.Rotate the axis to the original orientation 5.Translate the rotation axis to the original position Basic Idea 1.Translate (x1, y1, z1) to the origin 2.Rotate (x’2, y’2, z’2) on to the z axis 3.Rotate the object around the z-axis 4.Rotate the axis to the original orientation 5.Translate the rotation axis to the original position (x 2,y 2,z 2 ) (x 1,y 1,z 1 ) x z y R -1 T -1 R R T T
General 3D Rotations Step 1. Translation (x 2,y 2,z 2 ) (x 1,y 1,z 1 ) x z y
General 3D Rotations Step 2. Establish [ T R ] x x axis (a,b,c) (0,b,c) Projected Point Rotated Point x y z
Arbitrary Axis Rotation Step 3. Rotate about y axis by (a,b,c) (a,0,d) l d x y Projected Point z Rotated Point
Arbitrary Axis Rotation Step 4. Rotate about z axis by the desired angle l y x z
Arbitrary Axis Rotation Step 5. Apply the reverse transformation to place the axis back in its initial position x y l l z
Find the new coordinates of a unit cube 90º-rotated about an axis defined by its endpoints A(2,1,0) and B(3,3,1). A Unit Cube Example
Step1. Translate point A to the origin A’(0,0,0) x z y B’(1,2,1)
x z y l Projected point (0,2,1) B”(1,0, 5) Example Step 2. Rotate axis A’B’ about the x axis by and angle , until it lies on the xz plane.
x z y l B”(1,0, 5) (0,0, 6) Example Step 3. Rotate axis A’B’’ about the y axis by and angle , until it coincides with the z axis.
Example Step 4. Rotate the cube 90° about the z axis –Finally, the concatenated rotation matrix about the arbitrary axis AB becomes,
Example
Multiplying R(θ) by the point matrix of the original cube
Questions? 9/5/2015