Quick Overview: Linear Algebra (with a focus on concepts needed for basic graphics)

# Quick Overview: Linear Algebra (with a focus on concepts needed for basic graphics)

Télécharger la présentation

## Quick Overview: Linear Algebra (with a focus on concepts needed for basic graphics)

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
##### Presentation Transcript

1. Quick Overview: Linear Algebra(with a focus on concepts needed for basic graphics) 22C:151 Computer Graphics

2. Representations in 3D • What is a: • Scalar ? • Point ? • Vector ?

3. Representations in 3D • What is a: • Scalar • A normal number that you’re familiar with • Point • A location in space. ( Usually represented (x,y,z) ) • Vector • A “direction.” ( Usually represented (x,y,z) ) • Has a length and an orientation (think a compass direction) • Q: What is thedifference between points and vectors?

4. Representations in 3D • Properties of a scalar: • Standard mathematical properties • Arithmetic operations work as expected: +, -, *, ÷ • Additive inverse: a + (-a) = 0 • Multiplicative inverse: a * (1/a) = 1

5. Representations in 3D • Properties of a point: • Q: Can you add points? • Q: Can you subtract points? • Q: Can you multiply points? • Q: Can you divide points? • Q: Does a point have an additive inverse? • Q: Does a point have a multiplicative inverse?

6. Representations in 3D • Properties of a point: • Is just a location in space • Most mathematical operations don’t make sense on points

7. Representations in 3D • Properties of a vector: • Has a direction and a magnitude (distance) • A concrete example: giving directions • “Go North for 3 miles” defines a vector • It points in a northerly direction and has a magnitude of 3 miles • Q: Can you add vectors? (What does it mean?) • Q: Can you subtract vectors? (What does it mean?) • Q: Can you multiply vectors? • Q: Can you invert vectors? (Additive? Multiplicative?)

8. Representations in 3D • Q: How about mixed operations? • What can you do with a point and a scalar? • What can you do with a point and a vector? • What can you do with a vector and a scalar?

9. Representations in 3D • Valid mixed operations: • Point + Vector → move the point • Point – Vector → move in opposite direction • Scalar * Vector → change vector length • Vector / Scalar → change vector length • Others do not really make sense • ( What would “scaling” an infinitesimal point mean? )

10. Special Vector Operations • Some other non-arithmetic operations common on vectors: Find angle between two vectors Project v2 onto v1 to compute v3 Given v1 and v2, find v3 perpendicular to both v3 v2 v2 v2 Ѳ v1 v3 v1 v1 Why? Lighting of surface varies based on angle between viewer and light source Why? Projection could be used to put the shadow of an object on the ground Why? Given edges of a triangle, we might want to find which direction it faces

11. Special Vector Operations Find angle between two vectors Project v2 onto v1 to compute v3 v2 v2 • Both can be done with a dot product operation • v1 · v2 = length( v1 ) * length( v2 ) * cosѲ • So if both vectors have unit length: • Ѳ = acos( v1 · v2 ) • And v3 = ( v1 · v2 ) * v1 Ѳ v1 v3 v1

12. Special Vector Operations • The definition of a dot product: If a = (ax, ay, az) and b = (bx, by, bz) a · b = ax * bx + ay * by + az * bz or a · b = len( a ) * len( b ) * cosѲ

13. Special Vector Operations • Can be done with a cross product operation: v3 = v1 × v2 Given v1 and v2, find v3 perpendicular to both v3 v2 v1

14. Special Vector Operations • The definition of a cross product: If a = (ax, ay, az) and b = (bx, by, bz) Then: a × b = ( aybz – azby , azbx – axbz , axby – aybx )

15. Other Interesting Properties • Finding the length of a vector: ( len ( a ) )2 = a · a • Vector “normalization” (making a unit vector): vunit = v / len( v ) = v / sqrt( v · v )

16. Point, Vectors, Scalars • Questions?

17. Coordinate Spaces • Q: Is it possible for both you and your friend to live at the address 700 7th Avenue and not live in the same building?

18. Coordinate Spaces • Q: Is it possible for both you and your friend to live at the address 700 7th Avenue and not live in the same building? Of course…. Iowa City Coralville

19. Coordinate Spaces • Q: If I said “Leave 700 7th Ave and go north for one mile,” where would you end up?

20. Coordinate Spaces • Q: If I said “Leave 700 7th Ave and go north for one mile,” where would you end up? • You do not know • I did not give you enough information • I did not tell you which coordinate space the point (700 7th Ave) was located in: Iowa City’s or Coralville’s

21. Coordinate Spaces • Q: How far is it between 700 7th Ave and 800 7th Ave?

22. Coordinate Spaces • Q: How far is it between 700 7th Ave and 800 7th Ave? • Which place am I talking about? • Cannot do operations correctly without knowing

23. Coordinate Spaces • Key: Every point (x,y,z) has a coordinate space • Key: Every vector (x,y,z) has a coordinate space • This is not stored as part of the data • This means you have to remember its space

24. Coordinate Spaces • Q: Why is this important for graphics?

25. Coordinate Spaces • Q: Why is this important for graphics? • Graphics involves many coordinate spaces • Using the wrong one will give very bad results • Example: • Specify tire geometry relative to origin at center • Move the tire to “car space,” relative to car • Put the car into the world (called “world space”) • We’re interested in “eye space” (where you see it) • Project onto the screen (i.e., into “screen space”) (Even this simple example has 5 coordinate spaces!)

26. Changing Spaces • How to change from one space to another? • A transformation • Usually represented by a matrix • I think of a matrix as a function • Takes coordinates in one space into another • Similar to a function like RadiansToDegrees() • Would you call RadiansToDegrees() on a value already in degrees? • Similarly, there is a correct order to the application of matrices

27. What is a Matrix? • At a low level, it is a grid of numbers • A transform from m-dimensions to n-dimensions • We’re interested in 3D (and sometimes 4D) spaces • So our matrices will be either 3×3 or 4×4 m n

28. Matrix Mathematics • Matrices can be added together • Component by component

29. Matrix Mathematics • Matrices can be multiplied together • “Multiplying” a row by a column gives one entry in result • Notice this is really a dot product: • Row A1 dotted with Column B1 • Because of this, matrix multiplication is not commutative! • Reversing the order of multiplication changes the result

30. Matrix Mathematics • Matrices can be applied to vectors and points • A special case of matrix-matrix multiplication • Notice this is really a dot product • Row A1 dotted with vector V

31. So What Are They Good For? • Assume you’ve got a virtual world • Q: What operations might you do to geometry?

32. So What Are They Good For? • Assume you’ve got a virtual world • Q: What operations might you do to geometry? • Scaling • Translation • Rotation • Shear • Projection (e.g., on to screen) • Plus lots of deformations that are hard to describe: • Breaking, twisting, and other “non-rigid” deformations

33. Affine Transformations • Graphics deals mostly with “affine” transforms • Affine→ parallel lines stay parallel • Includes: • Rotation, Scale, Translation • Let’s explore these three affine transforms • Discuss: • Q: How should rotations, scales, and translations modify points, vectors, and triangles?

34. Affine Transformations • Scale: • How should points, vectors, and triangles be affected?

35. Affine Transformations • Scale: • How should points, vectors, and triangles be affected? • Vector → direction the same, magnitude scaled • Point → distance from origin scaled • Triangle • Consists of three points (as vertices) • Scaling all three points individually suggests: • Scale distance from origin • This also scales the edges by the same amount

36. Affine Transformations • Scale: • Scales by sx on x-axis, sy on y-axis, and sz on z-axis

37. Affine Transformations • Rotation: • How should points, vectors, and triangles be affected?

38. Affine Transformations • Rotation: • How should points, vectors, and triangles be affected? • Vector → magnitude the same, direction rotated • Point → distance to origin the same, direction to origin rotated • Triangle • Rotating all three points individually suggests: • Same distance from origin • Vertex location & edge directions rotated around origin

39. Affine Transformations • Rotation: • What should this matrix look like? • Consider diagram: Rotation by Ѳ

40. Affine Transformations • Rotation around z-axis: • How about if we wanted to rotate around x or y?

41. Affine Transformations Rotation around x-axis Rotation around y-axis Rotation around z-axis See: Ray Tracing from the Ground Up Chapter 20 Realistic Ray Tracing Page 115 OpenGL Programming Guide Appendix F

42. Affine Transformations Rotation around x-axis Rotation around y-axis Rotation around z-axis Q: What about rotations around arbitrary axes?

43. Affine Transformations • Arbitrary Rotations: • Somewhat complex, and no reason to know how to derive it • For a rotation of Ѳ around the vector v, the 3×3 rotation matrix is: • Where u, Smatr, and Imatr are:

44. Arbitrary Rotations • Example: • What is the matrix that rotates by 45° around the axis (2, 1, 2) ?

45. Affine Transformations • Translation: • How should points, vectors, and triangles be affected?

46. Affine Transformations • Translation: • How should points, vectors, and triangles be affected? • Vector → not affected! • Point → translated by specified amount • Triangle • Translating all three points individually suggests: • Whole triangle is moved • Edge lengths and directions remain the same

47. Affine Transformations • Translation: • What should a translation matrix look like? • Look at simple example, translate by 2 in x:

48. Affine Transformations • Remember: • Whatever matrix you choose needs to work for all input!

49. Homogeneous Coordinates • Key Observation: • Translations in 3D not possible with a 3×3 matrix! • Also, impossible to differentiate vectors and points • Both use the same 3D representation!

50. Homogeneous Coordinates • Key Observation: • Translations in 3D not possible with a 3×3 matrix! • Also, impossible to differentiate vectors and points • Both use the same 3D representation! • Solution: • “Homogeneous Coordinates” • A four dimensional representation • Allows translations and projections via matrix ops