1 / 115

Transformation Techniques in Computer Graphics

Explore the fundamentals of transformations in computer graphics, including 2D and 3D transformations, matrix representations, scaling, and rotation. Gain a deeper understanding of how these techniques are used to manipulate objects in a graphical environment.

jeannineg
Download Presentation

Transformation Techniques in Computer Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. http://www.ugrad.cs.ubc.ca/~cs314/Vmay2005 Transformations I, II, IIIWeek 1, Thu May 12

  2. Reading • FCG Chap 5 (except 5.1.6, 5.3.1) • FCG pages 224-225 • RB Chap Viewing: • Sect. Viewing and Modeling Transforms until Viewing Transformations • Sect. Examples of Composing Several Transformations through Building an Articulated Robot Arm • RB Appendix Homogeneous Coordinatesand Transformation Matrices • until Perspective Projection • RB Chapter Display Lists • (it’s short)

  3. Textbook Errata • list at http://www.cs.utah.edu/~shirley/fcg/errata • math review: also p 48 • a x (b x c) != (a x b) x c • transforms: p 91 • should halve x (not y) in Fig 5.10 • transforms: p 106 • second line of matrices: [xp, yp, 1]

  4. Correction: Vector-Vector Subtraction • subtract: vector - vector = vector 2 argument reversal

  5. Correction: Vector-Vector Multiplication • multiply: vector * vector = scalar • dot product, aka inner product u2 • geometric interpretation • lengths, angles • can find angle between two vectors

  6. Correction: Matrix Multiplication • can only multiply (n,k) by (k,m)number of left cols = number of right rows • legal • undefined

  7. Correction: Matrices and Linear Systems • linear system of n equations, n unknowns • matrix form Ax=b 1

  8. Geometry Database Model/View Transform. Perspective Transform. Lighting Clipping Frame- buffer Texturing Scan Conversion Depth Test Blending Review: Rendering Pipeline

  9. Correction: Scan Conversion Geometry Database Model/View Transform. Perspective Transform. Lighting Clipping • scan conversion • turn 2D drawing primitives (lines, polygons etc.) into individual pixels (discretizing/sampling) • interpolate color across primitive • generate discrete fragments Scan Conversion

  10. Correction: Blending Geometry Database Model/View Transform. Perspective Transform. Lighting Clipping Texturing Scan Conversion Depth Test Blending • blending • final image: write fragments to pixels • draw from farthest to nearest • no blending – replace previous color • blending: combine new & old values with arithmetic operations

  11. Geometry Database Model/View Transform. Perspective Transform. Lighting Clipping Frame- buffer Texturing Scan Conversion Depth Test Blending Correction: Framebuffer • framebuffer • video memory on graphics board that holds image • double-buffering: two separate buffers • draw into one while displaying other, then swap • allows smooth animation, instead of flickering

  12. Review: OpenGL • pipeline processing, set state as needed void display() { glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.0, 1.0, 0.0); glBegin(GL_POLYGON); glVertex3f(0.25, 0.25, -0.5); glVertex3f(0.75, 0.25, -0.5); glVertex3f(0.75, 0.75, -0.5); glVertex3f(0.25, 0.75, -0.5); glEnd(); glFlush(); }

  13. Review: Event-Driven Programming • main loop not under your control • vs. procedural • control flow through event callbacks • redraw the window now • key was pressed • mouse moved • callback functions called from main loop when events occur • mouse/keyboard state setting vs. redrawing

  14. Transformations

  15. Overview • 2D Transformations • Homogeneous Coordinates • 3D Transformations • Composing Transformations • Transformation Hierarchies • Display Lists • Transforming Normals • Assignments

  16. Transformations • transforming an object = transforming all its points • transforming a polygon = transforming its vertices

  17. Matrix Representation • represent 2D transformation with matrix • multiply matrix by column vector apply transformation to point • transformations combined by multiplication • matrices are efficient, convenient way to represent sequence of transformations!

  18. Scaling • scaling a coordinate means multiplying each of its components by a scalar • uniform scaling means this scalar is the same for all components:  2

  19. X  2,Y  0.5 Scaling • non-uniform scaling: different scalars per component: • how can we represent this in matrix form?

  20. Scaling • scaling operation: • or, in matrix form: scaling matrix

  21. 2D Rotation counterclockwise RHS (x′, y′) (x, y) x′ = x cos() - y sin() y′ = x sin() + y cos() 

  22. 2D Rotation From Trig Identities x = r cos (f) y = r sin (f) x′ = r cos (f + ) y′ = r sin (f + ) Trig Identity… x′ = r cos(f) cos() – r sin(f) sin() y′ = r sin(f) cos() + r cos(f) sin() Substitute… x ′ = x cos() - y sin() y ′ = x sin() + y cos() (x′, y′) (x, y)  f

  23. 2D Rotation Matrix • easy to capture in matrix form: • even though sin(q) and cos(q) are nonlinear functions of q, • x′ is a linear combination of x and y • y′ is a linear combination of x and y

  24. 2D Rotation: Another Derivation (x′,y′) q (x,y)

  25. 2D Rotation: Another Derivation (x′,y′) q (x,y) y x

  26. 2D Rotation: Another Derivation (x′,y′) q y x (x,y) q y x

  27. 2D Rotation: Another Derivation (x′,y′) ' x B (x,y) A

  28. 2D Rotation: Another Derivation (x′,y′) ' x B x (x,y) q x A

  29. 2D Rotation: Another Derivation (x′,y′) B ' q x q y (x,y) q q y x A

  30. Shear • shear along x axis • push points to right in proportion to height y y x x

  31. Shear • shear along x axis • push points to right in proportion to height y y x x

  32. Reflection • reflect across x axis • mirror x x

  33. Reflection • reflect across x axis • mirror x x

  34. 2D Translation (x’,y’) (x,y)

  35. 2D Translation (x′,y′) (x,y) scaling matrix rotation matrix

  36. 2D Translation vector addition (x′,y′) (x,y) matrix multiplication matrix multiplication scaling matrix rotation matrix

  37. 2D Translation vector addition (x′,y′) (x,y) matrix multiplication matrix multiplication scaling matrix rotation matrix translation multiplication matrix??

  38. Linear Transformations • linear transformations are combinations of • shear • scale • rotate • reflect • properties of linear transformations • satisifes T(sx+ty) = s T(x) + t T(y) • origin maps to origin • lines map to lines • parallel lines remain parallel • ratios are preserved • closed under composition

  39. Challenge • matrix multiplication • for everything except translation • how to do everything with multiplication? • then just do composition, no special cases • homogeneous coordinates trick • represent 2D coordinates (x,y) with 3-vector (x,y,1)

  40. Homogeneous Coordinates • our 2D transformation matrices are now 3x3: use rightmost column

  41. Homogeneous Coordinates Geometrically point in 2D cartesian y x

  42. cartesian homogeneous / w w w=1 y x Homogeneous Coordinates Geometrically • point in 2D cartesian + weight w =point P in 3D homog. coords • multiples of (x,y,w) • form a line L in 3D • all homogeneous points on L represent same 2D cartesian point • example: (2,2,1) = (4,4,2) = (1,1,0.5)

  43. cartesian homogeneous / w w w=1 y x Homogeneous Coordinates Geometrically • homogenize to convert homog. 3D point to cartesian 2D point: • divide by w to get (x/w, y/w, 1) • projects line to point onto w=1 plane • when w=0, consider it as direction • points at infinity • these points cannot be homogenized • lies on x-y plane • (0,0,0) is undefined

  44. Homogeneous Coordinates Summary • may seem unintuitive, but they make graphics operations much easier • allow all linear transformations to be expressed through matrix multiplication • use 4x4 matrices for 3D transformations

  45. Affine Transformations • affine transforms are combinations of • linear transformations • translations • properties of affine transformations • origin does not necessarily map to origin • lines map to lines • parallel lines remain parallel • ratios are preserved • closed under composition

  46. 3D Rotation About Z Axis general OpenGL command rotate in z glRotatef(angle,x,y,z); glRotatef(angle,0,0,1);

  47. 3D Rotation in X, Y around x axis: glRotatef(angle,1,0,0); around y axis: glRotatef(angle,0,1,0);

  48. 3D Scaling glScalef(a,b,c);

  49. 3D Translation glTranslatef(a,b,c);

  50. 3D Shear • shear in x • shear in y • shear in z

More Related