transformations projections 02
play

Transformations, Projections (02) RNDr. Martin Madaras, PhD. - PowerPoint PPT Presentation

Principles of Computer Graphics and Image Processing Transformations, Projections (02) RNDr. Martin Madaras, PhD. martin.madaras@stuba.sk Overview 2D Transformations Basic 2D transformations Matrix representation Matrix


  1. Matrix Composition  Be aware: order of transformations matters  Matrix multiplication is not commutative transformation order P’ = T * S * R * p “Global” “Local” 43

  2. Matrix Composition  Be aware: order of transformations matters  Matrix multiplication is not commutative 44

  3. Problem: local rotation angle φ 45

  4. Matrix Composition  Rotate around an arbitrary point (a,b)  Translate (a,b) to the origin  Rotate around origin  Translate back 46

  5. Matrix Composition  Rotate around an arbitrary point (a,b)  Translate (a,b) to the origin  Rotate around origin  Translate back M = T(a, b) * R( 𝜄 ) * T(-a, -b) 47

  6. Matrix Composition translate rotation center to origin: t(t x ,t y ) 1. rotate by φ 2. inverse translate by t´(-t x ,-t y ) 3. Matrix notation:         1 0 0 cos sin 0 1 0 0           = −     ( ' , ' , 1 ) ( , , 1 ) 0 1 0 sin cos 0 0 1 0 x y x y           − −   1 0 0 1 1 t t t t     x y x y 48

  7. Matrix Composition  Scale by sx, sy around arbitrary point (a, b)  Use the same approach … 49

  8. Matrix Composition  Scale by sx, sy around arbitrary point (a, b)  Use the same approach … M = T(a, b) * S( 𝑡 𝑦 , 𝑡 𝑧 ) * T(-a, -b) 50

  9. Overview  2D Transformations  Basic 2D transformations  Matrix representation  Matrix composition  3D Transformations  Basic 3D transformations  Same as 2D 51

  10. 3D Transformations  Right-handed coordinate system  Left-handed coordinate system  rotation direction 52

  11. 3D Transformations  Same idea as 2D transformations  Homogenous coordinates (x,y,z,w)  4x4 transformation matrices 𝑦 ′ 𝑏 𝑐 𝑑 𝑒 𝑦 𝑧 ′ 𝑓 𝑔 𝑕 ℎ 𝑧 = 𝑨 𝑨 ′ 𝑗 𝑘 𝑙 𝑚 𝑥 𝑛 𝑜 𝑝 𝑞 𝑥′ 53

  12. Basic 3D Transformations 𝑦 ′ 𝑡 𝑦 0 0 0 𝑦 ′ 𝑦 𝑦 1 0 0 0 𝑧 ′ 𝑧 ′ 𝑧 0 𝑡 𝑧 0 0 𝑧 0 1 0 0 = = 𝑨 ′ 𝑨 𝑨 𝑨 ′ 0 0 1 0 0 0 𝑡 𝑨 0 𝑥 𝑥 0 0 0 1 𝑥′ 0 0 0 1 𝑥′ Identity Scale 𝑦 ′ 𝑦 ′ 𝑦 1 0 0 𝑢 𝑦 𝑦 1 0 0 0 𝑧 ′ 𝑧 ′ 𝑧 𝑧 0 1 0 𝑢 𝑧 0 −1 0 0 = = 𝑨 𝑨 𝑨 ′ 𝑨 ′ 0 0 −1 0 0 0 1 𝑢 𝑨 𝑥 𝑥 0 0 0 1 𝑥′ 𝑥′ 0 0 0 1 Translation Mirror over X 54

  13. Basic 3D Transformations  Rotation around Z axis 𝑦 ′ 𝑦 cos 𝜄 −sin 𝜄 0 0 𝑧 ′ 𝑧 sin 𝜄 cos 𝜄 0 0 = 𝑨 𝑨 ′ 0 0 1 0 𝑥 0 0 0 1 𝑥′  Rotation around Y axis 𝑦 ′ 𝑦 cos 𝜄 0 sin 𝜄 0 𝑧 ′ 𝑧 0 1 0 0 = 𝑨 𝑨 ′ −sin 𝜄 0 cos 𝜄 0 𝑥 0 0 0 1 𝑥′  Rotation around X axis 𝑦 ′ 𝑦 1 0 0 0 𝑧 ′ 𝑧 0 cos 𝜄 −sin 𝜄 0 = 𝑨 𝑨 ′ 0 sin 𝜄 cos 𝜄 0 𝑥 0 0 0 1 𝑥′ 55

  14. Same as 2D  Everything else is the same as 2D  In fact 2D is actually 3D in OpenGL  z is either 0 or ignored 56

  15. How the lectures should look like #3 Ask questions, please!!! - Be communicative - www.slido.com #PPGSO02 - More active you are, the better for you! - 57

  16. Projections 58

  17. Projection  General definition:  Maps points in n-space to m-space (m<n)  In Computer Graphics:  Map 3D camera coordinates to 2D screen coordinates 59

  18. Viewing transformation Convert from local/world coordinates to  camera/viewport coordinates rotate scene so that camera lies in z-axis 1. projection transformation 2. viewport transformation 3. 60

  19. Stage 0 61

  20. Stage 1 - translate P→P’ 62

  21. Stage 2 - rotate P’→P’’→P’’’ 63

  22. Stage 2 - rotate P’→P’’→P’’’ 64

  23. Orthogonal projection 65

  24. Orthogonal projection  𝑦 𝑄 = x’’’  𝑧 𝑄 = y’’’  z’’’ is simply left out  Matrix notation   1 0 0 0     0 1 0 0 = ( , , , 1 ) ( ' ' ' , ' ' ' , ' ' ' , 1 ) x y z x y z   P P p 0 0 0 0       0 0 0 1 66

  25. Perspective projection 67

  26. Taxonomy of Projections 68

  27. Taxonomy of Projections 69

  28. Parallel Projection  Center of projection is at infinity  Direction of projection (DOP) same for all points 70

  29. Orthographic Projections  DOP perpendicular to view plane 71

  30. Oblique Projections  DOP not perpendicular to view plane 72

  31. Parallel Projection View Volume 73

  32. Parallel Projection Matrix  General parallel projection transformation 74

  33. Taxonomy of Projections 75

  34. Perspective Projection  Maps points onto a view plane along projectors emitting from center of projection (COP) 76

  35. Perspective Projection  N-point perspective  How many vanishing points? 3-point 2-point 1-point perspective perspective perspective 77

  36. Perspective Projection  Compute 2D coordinates from 3D coordinates using triangle similarity principle 78

  37. Perspective Projection  Compute 2D coordinates from 3D coordinates using triangle similarity principle 79

  38. Perspective Projection  4x4 matrix representation  𝑦 𝑇 = 𝑦 𝐷 𝐸/𝑨 𝐷  𝑧 𝑇 = 𝑧 𝐷 𝐸/𝑨 𝐷  𝑨 𝑇 = 𝐸  𝑥 𝑇 = 1 𝑦 𝑡 𝑦 𝑑 𝑏 𝑐 𝑑 𝑒 𝑧 𝑡 𝑧 𝑑 𝑓 𝑔 𝑕 ℎ = 𝑨 𝑡 𝑨 𝑑 𝑗 𝑘 𝑙 𝑚 𝑥 𝑡 𝑛 𝑜 𝑝 𝑞 1 80

  39. Perspective Projection  4x4 matrix representation  𝑦 𝑇 = 𝑦 𝐷 𝐸/𝑨 𝐷 𝑦 𝑇 = 𝑦 𝐷  𝑧 𝑇 = 𝑧 𝐷 𝐸/𝑨 𝐷 𝑧 𝑇 = 𝑧 𝐷 depth is stored 𝑨 𝑇 = 𝑨 𝐷  𝑨 𝑇 = 𝐸  𝑥 𝑇 = 1 𝑥 𝑇 = 𝑨 𝐷 /𝐸 𝑦 𝑡 𝑦 𝑑 𝑏 𝑐 𝑑 𝑒 𝑧 𝑡 𝑧 𝑑 𝑓 𝑔 𝑕 ℎ = 𝑨 𝑡 𝑨 𝑑 𝑗 𝑘 𝑙 𝑚 𝑥 𝑡 𝑛 𝑜 𝑝 𝑞 1 81

  40. Perspective Projection  4x4 matrix representation  𝑦 𝑇 = 𝑦 𝐷 𝐸/𝑨 𝐷 𝑦 𝑇 = 𝑦 𝐷  𝑧 𝑇 = 𝑧 𝐷 𝐸/𝑨 𝐷 𝑧 𝑇 = 𝑧 𝐷  𝑨 𝑇 = 𝐸 𝑨 𝑇 = 𝑨 𝐷  𝑥 𝑇 = 1 𝑥 𝑇 = 𝑨 𝐷 /𝐸 𝑦 𝑡 𝑦 𝑑 1 0 0 0 𝑧 𝑡 𝑓 𝑔 𝑕 ℎ 𝑧 𝑑 = 𝑨 𝑡 𝑨 𝑑 𝑗 𝑘 𝑙 𝑚 𝑥 𝑡 𝑛 𝑜 𝑝 𝑞 1 82

  41. Perspective Projection  4x4 matrix representation  𝑦 𝑇 = 𝑦 𝐷 𝐸/𝑨 𝐷 𝑦 𝑇 = 𝑦 𝐷  𝑧 𝑇 = 𝑧 𝐷 𝐸/𝑨 𝐷 𝑧 𝑇 = 𝑧 𝐷  𝑨 𝑇 = 𝐸 𝑨 𝑇 = 𝑨 𝐷  𝑥 𝑇 = 1 𝑥 𝑇 = 𝑨 𝐷 /𝐸 𝑦 𝑡 𝑦 𝑑 1 0 0 0 𝑧 𝑡 𝑧 𝑑 0 1 0 0 = 𝑨 𝑡 𝑨 𝑑 𝑗 𝑘 𝑙 𝑚 𝑥 𝑡 𝑛 𝑜 𝑝 𝑞 1 83

  42. Perspective Projection  4x4 matrix representation  𝑦 𝑇 = 𝑦 𝐷 𝐸/𝑨 𝐷 𝑦 𝑇 = 𝑦 𝐷  𝑧 𝑇 = 𝑧 𝐷 𝐸/𝑨 𝐷 𝑧 𝑇 = 𝑧 𝐷  𝑨 𝑇 = 𝐸 𝑨 𝑇 = 𝑨 𝐷  𝑥 𝑇 = 1 𝑥 𝑇 = 𝑨 𝐷 /𝐸 𝑦 𝑡 𝑦 𝑑 1 0 0 0 𝑧 𝑡 𝑧 𝑑 0 1 0 0 = 𝑨 𝑡 𝑨 𝑑 0 0 1 0 𝑥 𝑡 𝑛 𝑜 𝑝 𝑞 1 84

  43. Perspective Projection  4x4 matrix representation  𝑦 𝑇 = 𝑦 𝐷 𝐸/𝑨 𝐷 𝑦 𝑇 = 𝑦 𝐷  𝑧 𝑇 = 𝑧 𝐷 𝐸/𝑨 𝐷 𝑧 𝑇 = 𝑧 𝐷  𝑨 𝑇 = 𝐸 𝑨 𝑇 = 𝑨 𝐷  𝑥 𝑇 = 1 𝑥 𝑇 = 𝑨 𝐷 /𝐸 𝑦 𝑡 𝑦 𝑑 1 0 0 0 𝑧 𝑡 𝑧 𝑑 0 1 0 0 = 𝑨 𝑡 𝑨 𝑑 0 0 1 0 𝑥 𝑡 0 0 1/𝐸 0 1 85

  44. Perspective vs. Parallel  Perspective Projection  + Size varies inversely with distance - looks realistic  - Distance and angles are not (in general) preserved  - Parallel lines do not (in general) remain parallel  Parallel Projection  + Good for exact measurements  + Parallel lines remain parallel  - Angles are not (in general) preserved  - Less realistic looking 86

  45. Classical Projections 87

  46. Viewport transformation 88

  47. Viewport transformation  s x , s y – scale factors − − xv xv yv yv = = max min max min s x s y − − xc xc yc yc max min max min  Matrix notation   0 0 s   x =   ( , , 1 ) ( , , 1 ) 0 0 x y x y s v v p p y   − + − + 1 s xc xv s yc yv   x min min y min min 89

  48. Welcome to the matrix! local → global coordinates 1. translate, rotate, scale, translate  global → camera 2. translate, rotate, rotate, project  camera → viewport 3. translate, scale, translate  Transformation combine = matrix multiply  90

  49. 3D rendering pipeline 3D polygons Modeling 1 Transformation Lighting Model transformation local → global / world coordinates Viewing Viewport transformation Transformation global → camera Projection transformation Projection global → normalized device Transformation Clipping Rasterization Clipping Texturing & Lighting Scan Conversion 2D Image 91

  50. How the lectures should look like #2 Ask questions, please!!! - Be communicative - www.slido.com #PPGSO02 - More active you are, the better for you! - 92

  51. Fast Forward to Practical Assignment Bezier Curve 93

  52. Drawing Curves  Parametric curves  Both x and y are functions of additional parameter 94

  53. Drawing Curves  How to display? 95

  54. Drawing Curves  Draw many direct line segments  Careful at the ends  How long should each segment be? 96

  55. Drawing Curves  Draw many direct line segments  Careful at the ends  What about variable segment length? 97

  56. Drawing Curves  Midpoint-test subdivision 98

  57. Drawing Curves  Midpoint-test subdivision 99

  58. Drawing Curves  Midpoint-test subdivision 100

Recommend


More recommend