500 likes | 804 Views
Lecture 03: Linear Algebra. COMP 175: Computer Graphics January 28, 2014. Linear Algebra for 3D Graphics. Linear Algebra that you should know… 3D Coordinate Geometry 3D Points and Vectors dot products and cross products Vector and Matrix notations and algebra
E N D
Lecture 03:Linear Algebra COMP 175: Computer Graphics January 28, 2014
Linear Algebra for 3D Graphics • Linear Algebra that you should know… • 3D Coordinate Geometry • 3D Points and Vectors • dot products and cross products • Vector and Matrix notations and algebra • Properties of matrix multiplication (associative property, but NOT communicative property) • Associative => (5 + 2) + 1 = 5 + (2 + 1) • Commutative => 5 +2 + 1 = 1 + 2 + 5 • Matrix operations (multiplication, transpose, inverse, etc.)
Y -1 5 5 -1 R2 4 -2 4 -2 3 3 -3 -3 R 1 X 2 -4 2 -4 1 1 -5 -5 -5 -5 -4 -4 -3 -3 -5 -4 -3 -2 -2 -1 -1 0 -2 -1 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 Y R 3 5 1 2 4 3 3 4 2 5 1 Z 1024 1024 5 1 2 3 4 5 1 2 3 4 Cartesian Coordinate System • 1D, 2D, and 3D real coordinate spaces • Compare this with positive integer coordinate spaces “normal” coordinate axes computer screen axes 1024 … 1024 0 … … … 0
Y Point at (2, 3) -1 5 5 -1 R2 4 4 -2 -2 3 3 -3 -3 X 2 2 -4 -4 1 1 -5 -5 -5 -4 -3 -5 -4 -3 -2 -1 -2 -1 1 1 2 2 3 3 4 4 5 5 Y R 3 Point at (4, -2, 3) Z Points • Denotes a location in the Cartesian coordinate system
Vectors • Denotes: • Magnitude • Direction • NO POSITION!! • In , a vector can be defined as an ordered d-tuple: • A vector is often written as for clarity
Vectors • Because a vector has no position, one way to think of a 2D vector is as an “offset from the origin”. • Such offset can be translated (moved around)
Vectors - Length • Find the length of the following vector:
Vectors - Length • the Euclidean length of a 2D vector is: • The length of a -dimensional vector is: • Question: Can you prove it? • Note that the length of a vector is sometimes called the “norm” of the vector
Vectors – Scalar Multiple • For a vector , the vector can be multiplied by a scalar value such that the resulting vector is: • Question: what happens when is negative?
Vectors – Scalar Multiple • Examples of scalar multiples of the vector • These vectors are said to be parallel to the vector . • Question: What happens if ?
Vectors – Unit Vector • If I don’t care about magnitude of the vector – that is, all I care about is the direction, I can represent the vector such that: • This vector is said to be a “unit vector” (often denoted as , called v-hat), and the process of making a vector be of length = 1 is called “normalization”.
Vectors – Unit Vector • Question: Given a vector , how do you find ? • Question: Can every vector be normalized?
5 5 10 10 9 9 4 4 8 8 3 3 2 7 2 7 1 1 6 6 1 1 2 2 3 3 5 5 4 4 6 6 7 7 8 8 9 9 10 10 v + u v v u u Vectors - Addition • Addition of vectors is commutative (and associative).
5 5 10 10 9 9 4 4 8 8 3 3 2 7 2 7 1 1 6 6 1 1 2 2 3 3 5 5 4 4 6 6 7 7 8 8 9 9 10 10 u+ v v v u u Vectors - Addition • Addition of vectors is commutative (and associative).
5 5 10 10 9 9 4 4 3 8 3 8 7 2 7 2 1 1 6 6 1 1 2 2 3 3 5 5 4 4 6 6 7 7 8 8 9 9 10 10 v + u u+ v v v u u Vectors – Addition • Given two vectors, Which is equal to:
5 4 -1 -2 3 2 -3 -4 1 -4 -3 -2 -1 1 2 3 4 5 Vectors - Subtraction • Subtraction works the same as addition (with negative values): • Given two vectors, v u -u -u
2 1 1.8 0.8 0.6 1.6 0.4 1.4 0.2 1.2 0.2 0.4 0.6 1 0.8 1.2 1.4 1.6 1.8 2 Vectors – Basis • Give two vectors , and • There are two interesting things about , and : • They are perpendicular to each other • They are both unit vectors
2 1 1.8 0.8 0.6 1.6 0.4 1.4 0.2 1.2 0.2 0.4 0.6 1 0.8 1.2 1.4 1.6 1.8 2 Vectors – Basis • For , and : • They are perpendicular to each other (, and are said to be “orthogonal” to each other) • They are both unit vectors • These two vectors form the 2D Cartesian Coordinate System. • We can say that and are the “basis vectors” of the 2D Cartesian Coordinate System
Vector - Basis • For , and , we say that the two vectors form an “orthonormal basis” because they: • Are orthogonal to each other, and • Are both unit vectors
5 10 9 4 3 8 2 7 1 6 1 2 3 5 4 6 7 8 9 10 Vectors – Basis • It turns out, any two “linearly independent” vectors, , can form a 2D basis. • In other words, given a vector , we can always express as a linear combination of the basis vectors
Vector - Basis • More formally, given a 2D vector , we can express it using two basis vectors and : • Question: Can you think of two vectors that CANNOT form basis vectors for a 2D space? • (Hint: think linear independence)
OK not OK not OK OK Vector - Basis • The last two conditions are NOT ok because the two vectors are “linearly dependent”. • That is, one vector is the scalar multiple of the other
Algebraic Properties of Vectors • Commutative: • Associative: • Additive identity: there is a vector 0 (the null vector), such that: • Additive inverse: • Distributive (vector): • Distributive (scalar): v • Multiplicative identity: For any
Vector – Cross Product • The Cross Product of two vectors is a vector that is perpendicular to both original vectors. That is, it is normal to the plane containing the two vectors. • Given two vectors and , the dot product is written as .
Vector – Cross Product • Important Note: • Cross Product is not commutative. That is: • In fact, • The “Right Hand Rule”
Vector – Cross Product • More formally: the cross product of and is written as: , and is defined as:
Vector – Cross Product • In addition, it is important to note that: • That is, the cross product of two vectors is not a normal vector. • In fact, where is the angle between the two vectors and . • What is the area of a parallelogram?
Vector – Cross Product • If you think about it, this equation: • says that the magnitude of the cross product is “how perpendicular and are” • Hint, think about the . If , then • Since the magnitude of a 3D vector is: • We can think of the cross product as the “magnitude” of the sum of the x, y, and z components
Vector – Cross Product • Deriving the cross product… For a simple 2D Case:
Vector – Cross Product • When the axes are x and y, we get: • We could have easily labeled the axes as y and z, or z and x, and we would get: • In other words, if we take two 3D vectors, and project them down to the (x,y), (y,z), and (z,x) planes, we could get the areas of the parallelogram in each of the planes.
Vector – Cross Product • Since we can think of the (x,y) plane as defined by a unit vector at the origin (0, 0, 0). Meaning that we can think of the relationship as: , we can rewrite the previous equations as: • Similarly:
Vector – Cross Product • Or more simply:
Vector – Cross Product • Another way to derive the cross product: • Let’s say that we’re in , which is formed by three orthonormal basis vectors: • If it makes things easier, you can imagine , , and . • Based on our definition of the cross product: , , , ,
Vector – Cross Product • Given two and , we can rewrite each as a sum of its components in the i, j, k basis, such that: , and • So
Vector – Cross Product • One More Thought: • For those of you who are ninja’s in linear algebra. You might have already noticed that: • Recall that the determinant of a matrix is:
Vector – Cross Product • Recall that the determinant of a matrix is: • Organize the terms a little bit, and you get:
Vector – Dot Product • Basic Formula: • For two vectors, and , the dot product (or “inner product” or “scalar product”) is defined as: • Or,
Vector – Dot Product • As it turns out, if and are two non-zero vectors:
Vector – Dot Product • This is important because if I want to know the angle between two vectors, I can trivially compute: • Note that if both and are unit vectors, then: • Note that will be in radians (that is, )
Vector – Dot Product • Other useful things with dot products • What are the results?
Vector – Dot Product • Other useful things with dot products
Vector – Dot Product • Determining “front” vs. “back” facing triangles • Back-face culling
5 4 3 2 1 -5 -4 -3 -2 -1 1 2 3 4 5 Vector – Dot Product • Example: • Perpendicular vectors always have a dot product of 0 because the cosine of 90o is 0 • For , and
v u Vector – Dot Product • More use of the Dot Product: Finding the length of a projection • If is a unit vector, then is the length of the projection of onto the line containing Recall dot product: If = 1, then u’
radius = ||v|| |v| sin() |v| cos() Vector – Dot Product • Prove that: • By trigonometric identity: (see proof: http://www.themathpage.com/atrig/sum-proof.htm) • So,
Exercises: • What is the result? A point , a vector , or a scalar ? • Show that is orthogonal to both and