3 D Graphics

4,271 views
4,110 views

Published on

Published in: Technology, Art & Photos
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,271
On SlideShare
0
From Embeds
0
Number of Embeds
25
Actions
Shares
0
Downloads
0
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide

3 D Graphics

  1. 1. 3D Graphics A Lecture By Abdul Ghaffar
  2. 2. Contents <ul><ul><li>2D a1ffine transformation 5.2 </li></ul></ul><ul><ul><ul><li>Translation, Rotation, scaling, shearing </li></ul></ul></ul><ul><ul><ul><li>Inverse transformation </li></ul></ul></ul><ul><ul><ul><li>Properties of affine transformation </li></ul></ul></ul><ul><ul><li>Introduction to 3D (Not in book) </li></ul></ul><ul><ul><ul><li>3D wire frame model </li></ul></ul></ul><ul><ul><ul><li>Projection ( Chapter 7 ) </li></ul></ul></ul><ul><ul><ul><ul><li>Orthogonal (7.6.2) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Perspective (7.4.1) </li></ul></ul></ul></ul><ul><ul><li>3D Affine transformation 5.3 </li></ul></ul><ul><ul><ul><li>Translation, Rotation, scaling, shearing </li></ul></ul></ul><ul><ul><li>Unified composition of 3D A.T. 5.3.2 </li></ul></ul><ul><ul><li>Non affine transformation (Not in book) </li></ul></ul><ul><ul><ul><li>Fish eye </li></ul></ul></ul><ul><ul><ul><li>False perspective </li></ul></ul></ul>
  3. 3. 2D Affine Transformation 5.2 <ul><li>2D Ex.: Scaling and translation (shifting): —Window-to-viewport mapping. </li></ul><ul><li>More flexible control: Affine transformation – A staple in C. G. </li></ul>
  4. 4. 2D Affine Transformation 5.2 <ul><li>Purpose / Applications: </li></ul><ul><ul><li>Compose a “scene” out of a number of objects – Applied many instances. </li></ul></ul>
  5. 5. 2D Affine Transformation 5.2 <ul><li>Purpose / Applications: </li></ul><ul><ul><li>Design a single “motif”, then fashion the whole shape – Ex.: a snowflake. </li></ul></ul>
  6. 6. 2D Affine Transformation 5.2 <ul><li>Purpose / Applications: </li></ul><ul><ul><li>3) View an object from different vantage points – position and reorient a camera. </li></ul></ul>
  7. 7. 2D Affine Transformation 5.2 <ul><li>Purpose / Applications: </li></ul><ul><ul><li>4) Computer animation: Move objects  Shifting and rotating the local coordinate system. </li></ul></ul>
  8. 8. 2D Affine Transformation 5.2 <ul><li>Use the transformation with OpenGL: </li></ul><ul><ul><li>Graphics pipeline: A sequence of operations that applied to all points that are “sent through”. </li></ul></ul><ul><ul><li>Know how to adjust the CT (current transformation ) so that the desired transformation are produced. </li></ul></ul>
  9. 9. 2D Affine Transformation 5.2 <ul><li>5.2.1 Transforming Points and Objects: </li></ul><ul><ul><li>Concepts: P T > Q or Q = T(P) </li></ul></ul><ul><ul><ul><li>(the image of P under the mapping T). </li></ul></ul></ul><ul><ul><ul><li>The image of line L under T consists of the images of all points of L. </li></ul></ul></ul>
  10. 10. 2D Affine Transformation 5.2 <ul><li>5.2.1 Transforming Points and Objects: </li></ul><ul><ul><li>Affine transformations preserve lines: </li></ul></ul><ul><ul><ul><li>A straight line T > A straight line. </li></ul></ul></ul><ul><ul><ul><li>A complex warping for visual effect won’t preserve lines. </li></ul></ul></ul><ul><ul><li>The affine transformation is the most common transformation in C.G. because: </li></ul></ul><ul><ul><ul><li>(1) Make it easy to scale/ rotate/ reposition figures; </li></ul></ul></ul><ul><ul><ul><li>(2) Permit a compact matrix representation, which is easily combined with matrix multiplication. </li></ul></ul></ul>
  11. 11. The Affine transformations 5.2.1 <ul><li>Representation with matrix expressions: </li></ul><ul><li>For points: </li></ul><ul><li>For vectors: </li></ul><ul><ul><li>For affine transformation, the third row is always (0, 0, 1). </li></ul></ul>
  12. 12. Geometric Effects of Elementary 2D Affine transformations 5.2.3 <ul><li>Translation: </li></ul><ul><li>Q=P+ d , </li></ul><ul><li>Offset vector d : (m 13 , m 23 ). </li></ul><ul><li>Scaling: </li></ul><ul><li>– Scaling about the origin. </li></ul><ul><ul><li>If S x <0 or S y <0, then produce a reflection. </li></ul></ul><ul><ul><li>Ex.: S x =-1,  A mirror image by flipping it horizontally about the y-axis. </li></ul></ul><ul><ul><li>If S x =S y =S, then have a uniform scaling. </li></ul></ul>
  13. 13. Geometric Effects of Elementary 2D Affine transformations 5.2.3 <ul><li>Rotation: </li></ul><ul><li>rotation (CCW: θ>0 ) about the origin . </li></ul><ul><li>Shearing: </li></ul><ul><ul><li>M SR_x : Q x = P x + hP y , Q y = P y (unaffected). </li></ul></ul><ul><ul><li>The area of a figure is unchanged when </li></ul></ul><ul><ul><li>it is sheared. </li></ul></ul><ul><ul><li>Used to make italic letters (fonts). </li></ul></ul>
  14. 14. The Inverse of an Affine Transformation 5.2.4 <ul><li>Most of affine transformations are non-singular , i.e., det M = m 11 m 22 -m 12 m 21  0  The inverse of M must exist: </li></ul><ul><li>matrix of M (denoted as M * , consisting of cofactors ). </li></ul><ul><li>Purpose: Undo the effect of an affine transformation: </li></ul><ul><li>if Q = MP  then undo: P = M -1 Q . </li></ul>
  15. 15. The Inverse of an Affine Transformation 5.2.4 <ul><li>The elementary inverse transformations: </li></ul>
  16. 16. Composing Affine Transformations 5.2.5 <ul><ul><li>Composing the transformations (trfms.) : Combine several trfms. into one compound trfm. </li></ul></ul><ul><ul><li>When two affine trfms. are composed, the resulting trfm. is also affine. </li></ul></ul><ul><ul><li>W = M 2 (M 1 P) = (M 2 M 1 )P = MP, </li></ul></ul><ul><ul><li>where M = M 2 M 1 is one single matrix. </li></ul></ul><ul><ul><ul><li>Note : Pre-multiply (left-multiply) P with M. </li></ul></ul></ul>
  17. 17. Examples of Composing 2D Transformations 5.2.6 <ul><ul><li>Rotating ( θ) about an arbitrary point (V x ,V y ): </li></ul></ul><ul><ul><li>Translate to the origin (-V x ,-V y ); </li></ul></ul><ul><ul><li>Rotate through θ about the origin; </li></ul></ul><ul><ul><li>Translate back to (V x ,V y ). </li></ul></ul><ul><ul><li>where d x = -cos θ V x + sin θ V y + V x , </li></ul></ul><ul><ul><li>d y = -sin θ V x - cos θ V y + V y . </li></ul></ul>
  18. 18. Examples of Composing 2D Transformations 5.2.6 <ul><ul><li>Reflection about a tilted ( β ) line: </li></ul></ul><ul><ul><li>Rotate through β to x-axis; </li></ul></ul><ul><ul><li>Make a reflection about the </li></ul></ul><ul><ul><li>x-axis; </li></ul></ul><ul><ul><li>Rotate back to β position. </li></ul></ul>
  19. 19. 5.2.7 Some Useful Properties of Affine Transformations <ul><ul><li>Preserve affine combinations of points ( a matter of linearity ). </li></ul></ul><ul><ul><li>Explanation ( Expl. ): Suppose T is an affine trfm., and W=a 1 P 1 +a 2 P 2 , where a 1 +a 2 =1. => then T(W)=a 1 T( P 1 )+ a 2 T( P 2 ), is the same affine combination. </li></ul></ul><ul><ul><li>Preserve lines and planes ( collinearity & flatness ). </li></ul></ul><ul><ul><li>Expl. : A line, L(t)=(1-t)A+tB => Q(t)=(1-t)T(A)+tT(B), another line. </li></ul></ul><ul><ul><li>One plane, P(s,t)=sA+tB+(1-s-t)C => … Another plane. </li></ul></ul>
  20. 20. 5.2.7 Some Useful Properties of Affine Transformations (2) <ul><ul><li>Parallelism of lines and planes is preserved. </li></ul></ul><ul><ul><li>Consequence : Parallelograms map into parallelograms in 2D. And Parallelepipeds map into parallelepipeds in 3D. </li></ul></ul><ul><ul><li>The columns of the matrix reveal the the transformed coordinate frames. </li></ul></ul><ul><ul><li>Expl. : , M =( m 1 | m 2 | m 3 ). </li></ul></ul><ul><ul><li>The coordinate frame ( i , j , φ ) that is defined by φ=(0 0 1) T , i =(1 0 0) T , j =(0 1 0) T transforms into ( m 1 , m 2 , m 3 ). For example, m 1 = M i . The axes of the new coordinate frame are not necessarily perpendicular, nor must they be of unit length . </li></ul></ul>
  21. 21. Some Useful Properties of Affine Transformations ) 5.2.7
  22. 22. 5.2.7 Some Useful Properties of Affine Transformations (4) <ul><ul><li>Relative ratios are preserved. </li></ul></ul><ul><ul><li>Consequence : (a) Midpoints of lines map into midpoints. </li></ul></ul><ul><ul><li>(b) The diagonals of any parallelogram bisect each other (because any parallelogram is an affine transformed square). </li></ul></ul><ul><ul><li>(c) Preserve ellipses and ellipsoids, too. </li></ul></ul><ul><ul><li>Effect of transformations on the areas of figures. </li></ul></ul><ul><ul><li>Expl. : In 2D, (Area after trfm.)/(Area before trfm.) = |det M |. </li></ul></ul><ul><ul><li>In 3D, similar arguments apply (to the volume of an object). </li></ul></ul>
  23. 23. 5.2.7 Some Useful Properties of Affine Transformations (5) <ul><ul><li>Every affine transformation is composed of elementary operations. </li></ul></ul><ul><ul><li>Expl .: A matrix M can be factored into a product of elementary matrices in various ways. </li></ul></ul><ul><ul><li>(a) For 2D decomposition ( from right to left ): </li></ul></ul><ul><ul><li>M = (translation)(shear)(scaling)(rotation); </li></ul></ul><ul><ul><li>(b) For 3D decomposition : </li></ul></ul><ul><ul><li>M = (translation)(scaling)(rotation)(shear1)(shear2). </li></ul></ul><ul><ul><li>Self study : All examples and exercises </li></ul></ul>
  24. 24. 3D wire frame model <ul><li>A wireframe model captures he shape of a 3D object in two lists a vertex list and an edge list. </li></ul><ul><li>A wire frame model consist of a collection of points and a set of edges that connects pairs of points. Together the points and edges define the shape of the object. </li></ul>
  25. 25. 3D wire frame model
  26. 26. 3D wire frame model
  27. 27. 3D wire frame model
  28. 28. Drawing wire frame model <ul><ul><li>Problem: The real issue is How to draw a line defined in three dimensional space on a two dimensional drawing surface. </li></ul></ul><ul><ul><li>Solution: Remove a dimension in some fashion. </li></ul></ul><ul><ul><li>The general technique to be used for drawing a 3D line segment is </li></ul></ul><ul><ul><ul><li>Project each of its two endpoints to 2D point. </li></ul></ul></ul><ul><ul><ul><li>Draw a straight line between the two projected endpoints </li></ul></ul></ul><ul><ul><li>There are two types of of projection from 3D to 2D to do this. </li></ul></ul><ul><ul><ul><li>Orthographic Projection </li></ul></ul></ul><ul><ul><ul><li>Perspective Projection </li></ul></ul></ul>
  29. 29. Orthographic Projection <ul><li>Each point is projected by finding where a ray , projector drawn through the point and parallel to the z-axis hits the x, y-plane. In this case the xy-plane is called the viewplane . This is a special case of parallel projection , in which all projectors are parallel to one and other. This is called Orthographic because all the rays are orthogonal to the view plane. </li></ul>
  30. 30. Orthographic Projection
  31. 31. Perspective Projection 7.4.1 <ul><ul><ul><li>Fundamental operation: Projecting 3D point into 2D coordinates on a plane. </li></ul></ul></ul><ul><ul><ul><li>Construct local coordinate system on near plane </li></ul></ul></ul><ul><ul><ul><li>(x*,y*) = (N(P x /(-P z )), N(P y ,/(-P z )) </li></ul></ul></ul>
  32. 32. Perspective Projection 7.4.1 <ul><ul><li>Note: </li></ul></ul><ul><ul><ul><li>-P z achieves perspective foreshortening </li></ul></ul></ul><ul><ul><ul><li>P z =0 if P lies on plane z=0: Clip before projecting </li></ul></ul></ul><ul><ul><ul><li>If P z lies behind eye, also clipped before projecting. </li></ul></ul></ul><ul><ul><ul><li>N scales picture (size only) </li></ul></ul></ul><ul><ul><ul><li>Straight lines project to straight lines (proof given) </li></ul></ul></ul>
  33. 33. Perspective Projection 7.4.1 <ul><ul><li>Example: </li></ul></ul>Eye(0,0,2) Eye(0.5,0,2) Eye(2,5,2)
  34. 34. 5.3 3D Affine Transformations <ul><ul><li>Use the explicit coordinate frame: </li></ul></ul><ul><ul><li>P = (P x P y P z 1 ) T  P = φ + P x i + P y j + P z k . </li></ul></ul><ul><ul><li>Ex .: Q = T(P) = M P, i.e.: </li></ul></ul>
  35. 35. 5.3.1 The Elementary 3D Transformations <ul><li>Translation: </li></ul><ul><li>Scaling: </li></ul>=> shift vector: m =(m 14 , m 24 , m 34 ).
  36. 36. 5.3.1 The Elementary 3D Transformations <ul><li>Shearing: (along y-axis) </li></ul><ul><li>General: </li></ul>=> Q=(P x , fP x +P y , P z ).
  37. 37. 5.3.1 The Elementary 3D Transformations <ul><li>Rotations: </li></ul><ul><li>(about a coordinate axis) </li></ul><ul><li>Positive θ =CCW rotation. </li></ul>
  38. 38. 5.3.1 The Elementary 3D Transformations
  39. 39. 5.3.2 Composing 3D Affine Transformations <ul><li>Similar to the 2D case, M = M 2 M 1 . </li></ul><ul><ul><li>Any number of affine transformations can be composed in this way. </li></ul></ul>
  40. 40. 5.3.3 Combining Rotations <ul><li>One important distinction between 2D and 3D trfms. is the rotations combination . </li></ul><ul><ul><li>In 2D, R( β 1 ) and R( β 2 ) combine to produce R( β 1 + β 2 ). And the order makes no difference. </li></ul></ul><ul><ul><li>In 3D, the order does matter: 3D rotation matrices do not commute. </li></ul></ul><ul><li>Any 3D rotation can be obtained by three rolls about the x-, y-, and z-axes: the overall rotation </li></ul><ul><li>M = R z ( β 3 )R y ( β 2 )R x ( β 1 ), where β 1 , β 2 , and β 3 are called Euler angles . </li></ul><ul><ul><li>It takes three values to completely specify a rotation. </li></ul></ul><ul><ul><li>There are 12 possible orderings of the three individual rolls, and each uses different values for β 1 , β 2 , and β 3 . </li></ul></ul>
  41. 41. 5.3.3 Combining Rotations (2) <ul><li>Rotations about an arbitrary axis </li></ul><ul><ul><li>Euler’s Theorem : Any rotation (or sequence of rotations) about a point is equivalent to a single rotation about some axis through that point. </li></ul></ul><ul><ul><li>The Classic way: </li></ul></ul><ul><ul><ul><li>Perform two rotations so that </li></ul></ul></ul><ul><ul><ul><li>u becomes aligned with the x -axis </li></ul></ul></ul><ul><ul><ul><li>Do a x -roll through the angle β ; </li></ul></ul></ul><ul><ul><ul><li>Undo the two alignment </li></ul></ul></ul><ul><ul><ul><li>rotations to restore u . </li></ul></ul></ul><ul><ul><ul><li>R u ( β )=R y (-  )R z (  )R x ( β )R z (-  )R y (  ) </li></ul></ul></ul><ul><ul><ul><li>= … (5.33) on P.241. </li></ul></ul></ul>
  42. 42. 5.3.4 Properties of 3D Affine Transformations <ul><li>Note : Stated in terms of any 3D trfms. T (.) or M . </li></ul><ul><li>Preserve affine combinations of points. </li></ul><ul><li>Preserve lines and planes. </li></ul><ul><li>Parallelism of lines and planes is preserved. </li></ul><ul><li>The columns of the matrix reveal the the transformed coordinate frames. </li></ul><ul><li>Relative ratios are preserved. </li></ul><ul><li>Effect of trfms. on the volumes of figures. </li></ul><ul><li>Every affine transformation is composed of elementary operations. </li></ul>
  43. 43. Non affine transformation (Fish eye)
  44. 44. Non affine transformation (Fish eye)
  45. 45. Non affine transformation (Fish eye)
  46. 46. Non affine transformation (Fish eye)
  47. 47. Non affine transformation (Fish eye)
  48. 48. Non affine transformation ( False perspective)
  49. 49. Non affine transformation ( False perspective)

×