630 likes | 742 Views
Quick Overview: Linear Algebra (with a focus on concepts needed for basic graphics). 22C:151 Computer Graphics. Representations in 3D. What is a: Scalar ? Point ? Vector ?. Representations in 3D. What is a: Scalar A normal number that you’re familiar with Point
E N D
Quick Overview: Linear Algebra(with a focus on concepts needed for basic graphics) 22C:151 Computer Graphics
Representations in 3D • What is a: • Scalar ? • Point ? • Vector ?
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?
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
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?
Representations in 3D • Properties of a point: • Is just a location in space • Most mathematical operations don’t make sense on points
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?)
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?
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? )
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
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
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Ѳ
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
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 )
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 )
Point, Vectors, Scalars • Questions?
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?
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
Coordinate Spaces • Q: If I said “Leave 700 7th Ave and go north for one mile,” where would you end up?
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
Coordinate Spaces • Q: How far is it between 700 7th Ave and 800 7th Ave?
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
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
Coordinate Spaces • Q: Why is this important for graphics?
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!)
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
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
Matrix Mathematics • Matrices can be added together • Component by component
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
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
So What Are They Good For? • Assume you’ve got a virtual world • Q: What operations might you do to geometry?
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
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?
Affine Transformations • Scale: • How should points, vectors, and triangles be affected?
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
Affine Transformations • Scale: • Scales by sx on x-axis, sy on y-axis, and sz on z-axis
Affine Transformations • Rotation: • How should points, vectors, and triangles be affected?
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
Affine Transformations • Rotation: • What should this matrix look like? • Consider diagram: Rotation by Ѳ
Affine Transformations • Rotation around z-axis: • How about if we wanted to rotate around x or y?
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
Affine Transformations Rotation around x-axis Rotation around y-axis Rotation around z-axis Q: What about rotations around arbitrary axes?
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:
Arbitrary Rotations • Example: • What is the matrix that rotates by 45° around the axis (2, 1, 2) ?
Affine Transformations • Translation: • How should points, vectors, and triangles be affected?
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
Affine Transformations • Translation: • What should a translation matrix look like? • Look at simple example, translate by 2 in x:
Affine Transformations • Remember: • Whatever matrix you choose needs to work for all input!
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!
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