Presentation is loading. Please wait.

Presentation is loading. Please wait.

COS 397 Computer Graphics Svetla Boytcheva AUBG, Spring 2013.

Similar presentations


Presentation on theme: "COS 397 Computer Graphics Svetla Boytcheva AUBG, Spring 2013."— Presentation transcript:

1 COS 397 Computer Graphics Svetla Boytcheva AUBG, Spring 2013

2 Lecture 2 Ray Tracing & Transformations

3 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

4 Points and Vectors 9/5/2015

5 Points and Vectors Drawing systems of particles Determining coordinates of other objects Drawing objects 9/5/2015

6 Points and Vectors Points –(x,y,z) Representation –Absolute coordinates (point) –Relative coordinate (radius-vector) –Distance (vector) –Direction (vector)

7 Points in 3D 3D absolute coordinates P(x,y,z) y Z Y X x z

8 Radius-vector Relative coordinate (radius-vector) (0,0,0) P(x,y,z) y Z Y X x z

9 Length and Magnitude Calculating the length/magnitude –Requires reference point R |p|  x x x x zzzz  y y y yR Z Y X

10 Direction Determines the direction in 3D –This is not sufficient for complete orientation |p| Z Y X

11 Points and Vectors operations

12 Vectors representation Vectors (points) Vector defined by points X 1 and X 2

13 Examples Vector p(5,2,3) Vector q from point (3,0,8) to (0,2,7)

14 Point Vector: Point position and direction – Magnitude - Direction V P2P2 P1P1 x1x1 x2x2 y1y1 y2y2 Points and Vectors

15 Length Vector p length Unit vector –Vector with length=1

16 Examples Vector p(5,2,3) Vector p from (3,0,8) to (0,2,7)

17 Addition and Subtraction Vector can be added or subtracted only to other vector

18 Examples Addition of p(5,2,3) and q(-1,-1,1) Subtraction of q(-1,-1,1) and r(4,1,4)

19 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

20 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)

21 Examples Doubled vector p(5,2,3) Reversed vector q(-1,-1,1)

22 Unit Vector Unit vector Geometrical meaning –Vector with length = 1 –Preserves the direction –Can be applied only over non-zero vectors

23 Examples Unit vector of p(5,2,3) Check

24 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

25 exexexex p.q calculating Using unit axis vectors p eyeyeyey ezezezez Z Y X

26 Multiply Remember that Find

27 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)

28 Example Check whether the vectors are perpendicular –p(4,0,1) and q(-2,3,8) Solution

29 Scalar Product Definition For Cartesian Reference Frame Properties –Commutative –Distributive |V 2 |cos   V2V2 V1V1 Dot Product, Inner Product

30 Vector product Vector product and the result is vector –Angle  between two vectors Geometrical meaning –Finding normal vectors –Parallelogram Area

31 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

32 How to remember? Use right hand –Coordinate system PQR is right-hand Снимка: FreeDigitalPhotos.net

33 Unit Vectors exexexex eyeyeyey ezezezez exexexex eyeyeyey ezezezez Z Y X Z Y X + + + - - -

34 Calculation of pхq Using unit axis vectors

35 After vector product of unit vectors Regroup

36 Final Result

37 Vector Product Definition For Cartesian Reference Frame Properties –AntiCommutative –Not Associative –Distributive Cross Product, Outer Product V1V1 V2V2 V1  V2V1  V2  u

38 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)

39 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)

40 Inverse Matrix Definition –Non-singular matrix If and only if the determinant of the matrix is non-zero 2  2 matrix Properties

41 2D Geometric Transformations

42 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

43 Example: 2D Geometric Transformation Modeling Coordinates World Coordinates

44 Example: 2D Scaling Modeling Coordinates World Coordinates Scale(0.3, 0.3)

45 Example: 2D Rotation Modeling Coordinates Scale(0.3, 0.3) Rotate(-90) World Coordinates

46 Example: 2D Translation Modeling Coordinates Scale(0.3, 0.3) Rotate(-90) Translate(5, 3) World Coordinates

47 Example: 2D Geometric Transformation Modeling Coordinates World Coordinates Again?

48 Example: 2D Geometric Transformation Modeling Coordinates World Coordinates Scale Translate Scale Rotate Translate

49 Basic 2D Transformations Translation – Scale – Rotation – Shear –

50 Basic 2D Transformations Translation – Scale – Rotation – Shear – Transformations can be combined (with simple algebra)

51 Basic 2D Transformations Translation – Scale – Rotation – Shear –

52 Basic 2D Transformations Translation – Scale – Rotation – Shear –

53 Basic 2D Transformations Translation – Scale – Rotation – Shear –

54 Basic 2D Transformations Translation – Scale – Rotation – Shear –

55 Matrix Representation Represent a 2D Transformation by a Matrix Apply the Transformation to a Point Transformation Matrix Point

56 Matrix Representation Transformations can be combined by matrix multiplication Matrices are a convenient and efficient way to represent a sequence of transformations Transformation Matrix

57 2×2 Matrices What types of transformations can be represented with a 2×2 matrix? 2D Identity 2D Scaling

58 2×2 Matrices What types of transformations can be represented with a 2×2 matrix? 2D Rotation 2D Shearing

59 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)

60 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

61 2D Translation 2D translation can be represented by a 3×3 matrix –Point represented with homogeneous coordinates

62 Basic 2D Transformations Basic 2D transformations as 3x3 Matrices Translate Shear Scale Rotate

63 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 12 1 2 x y (2, 1, 1) or (4, 2, 2) or (6, 3, 3) Convenient Coordinate System to Represent Many Useful Transformations

64 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

65 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

66 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

67 Matrix Composition Transformations can be combined by matrix multiplication Efficiency with premultiplication –Matrix multiplication is associative

68 Matrix Composition Rotate by  around arbitrary point (a,b) – Scale by sx, sy around arbitrary point (a,b) – (a,b)

69 Pivot-Point Rotation TranslateRotateTranslate (x r,y r )

70 General Fixed-Point Scaling TranslateScaleTranslate (x f,y f )

71 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)

72 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 )

73 3D Geometric Transformation

74 Contents Translation Scaling Rotation Rotations with Quaternions Other Transformations Coordinate Transformations

75 Transformation in 3D Transformation Matrix 3  3 : Scaling, Reflection, Shearing, Rotation 3  1 : Translation 1  3 : Homogeneous representation 1  1 : Uniform global Scaling

76 3D Translation Translation of a Point x z y

77 3D Scaling Uniform Scaling x z y

78 Relative Scaling Scaling with a Selected Fixed Position xxx x z z zz y yy y Original positionTranslateScaling Inverse Translate

79 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

80 Coordinate-Axes Rotations Z-Axis Rotation X-Axis Rotation Y-Axis Rotation z y x z y x z y x

81 Order of Rotations Order of Rotation Affects Final Position –X-axis  Z-axis –Z-axis  X-axis

82 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

83 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

84 General 3D Rotations Step 1. Translation (x 2,y 2,z 2 ) (x 1,y 1,z 1 ) x z y

85 General 3D Rotations Step 2. Establish [ T R ]  x x axis (a,b,c) (0,b,c) Projected Point   Rotated Point x y z

86 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

87 Arbitrary Axis Rotation Step 4. Rotate about z axis by the desired angle   l y x z

88 Arbitrary Axis Rotation Step 5. Apply the reverse transformation to place the axis back in its initial position x y l l z

89 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

90 Step1. Translate point A to the origin A’(0,0,0) x z y B’(1,2,1)

91 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.

92 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.

93 Example Step 4. Rotate the cube 90° about the z axis –Finally, the concatenated rotation matrix about the arbitrary axis AB becomes,

94 Example

95 Multiplying R(θ) by the point matrix of the original cube

96 Questions? 9/5/2015


Download ppt "COS 397 Computer Graphics Svetla Boytcheva AUBG, Spring 2013."

Similar presentations


Ads by Google