Transcript 2
Mathematical Foundations; Display Technologies CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003 Admin ● Call roll ● Waiting list add policy ■ Fill out course action forms ■ I’ll collect, sign, and turn in after class David Luebke 2 7/27/2016 Mathematical Foundations ● Finishing a brief, informal review of some of the mathematical tools we’ll employ ■ Geometry (2D, 3D) ■ Trigonometry ■ Vector and affine spaces ○ Points, vectors, and coordinates ■ Dot and cross products ■ Linear transforms and matrices David Luebke 3 7/27/2016 Recap: 3D Geometry ● To model, animate, and render 3D scenes, we must specify: ■ Location ■ Displacement from arbitrary locations ■ Orientation ● We’ll look at two types of spaces: ■ Vector spaces ■ Affine spaces ● We will often be sloppy about the distinction David Luebke 4 7/27/2016 Recap: Vector Spaces ● Given a basis for a vector space: ■ Each vector in the space is a unique linear combination of the basis vectors ■ The coordinates of a vector are the scalars from this linear combination ■ Best-known example: Cartesian coordinates ■ Note that a given vector will have different coordinates for different bases David Luebke 5 7/27/2016 Vectors And Points ● We commonly use vectors to represent: ■ Direction (i.e., orientation) ■ Points in space (i.e., location) ■ Displacements from point to point ● But we want points and directions to behave differently ■ Ex: To translate something means to move it without changing its orientation ■ Translation of a point = different point ■ Translation of a direction = same direction David Luebke 6 7/27/2016 Affine Spaces ● To be more rigorous, we need an explicit notion of position ● Affine spaces add a third element to vector spaces: points (P, Q, R, …) Q ● Points support these operations ■ Point-point subtraction: Q-P=v ○ Result is a vector pointing from P to Q ■ Vector-point addition: P + v = Q ○ Result is a new point ○ P+0=P v P ■ Note that the addition of two points is not defined David Luebke 7 7/27/2016 Affine Spaces ● Points, like vectors, can be expressed in coordinates ■ The definition uses an affine combination ■ Net effect is same: expressing a point in terms of a basis ● Thus the common practice of representing points as vectors with coordinates ● Be careful to avoid nonsensical operations ■ Point + point ■ Scalar * point David Luebke 8 7/27/2016 Affine Lines: An Aside ● Parametric representation of a line with a direction vector d and a point P1 on the line: P(a) = Porigin + ad ● Restricting 0 a produces a ray ● Setting d to P - Q and restricting 0 a 1 produces a line segment between P and Q David Luebke 9 7/27/2016 Dot Product ● The dot product or, more generally, inner product of two vectors is a scalar: v1 • v2 = x1x2 + y1y2 + z1z2 (in 3D) ● Useful for many purposes ■ Computing the length of a vector: length(v) = sqrt(v • v) ■ Normalizing a vector, making it unit-length ■ Computing the angle between two vectors: u • v = |u| |v| cos(θ) ■ Checking two vectors for orthogonality v ■ Projecting one vector onto another θ u David Luebke 10 7/27/2016 Cross Product ● The cross product or vector product of two vectors is a vector: y1 z 2 y 2 z1 v1 v 2 ( x1 z 2 x 2 z1) x1 y 2 x 2 y1 ● Cross product of two vectors is orthogonal to both ● Right-hand rule dictates direction of cross product ● Cross product is handy for finding surface orientation ■ Lighting ■ Visibility David Luebke 11 7/27/2016 Linear Transformations ● A linear transformation: ■ Maps one vector to another ■ Preserves linear combinations ● Thus behavior of linear transformation is completely determined by what it does to a basis ● Turns out any linear transform can be represented by a matrix David Luebke 12 7/27/2016 Matrices ● By convention, matrix element Mrc is located at row r and column c: M11 M12 M21 M22 M Mm1 Mm2 M1n M2n Mmn ● By (OpenGL) convention, vectors are columns: David Luebke 13 v1 v v 2 v 3 7/27/2016 Matrices ● Matrix-vector multiplication applies a linear transformation to a vector: M11 M12 M13 vx M v M 21 M 22 M 23 vy M31 M32 M33 vz ● Recall how to do matrix multiplication David Luebke 14 7/27/2016 Matrix Transformations ● A sequence or composition of linear transformations corresponds to the product of the corresponding matrices ■ Note: the matrices to the right affect vector first ■ Note: order of matrices matters! ● The identity matrix I has no effect in multiplication ● Some (not all) matrices have an inverse: M 1 Mv v David Luebke 15 7/27/2016