Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 03: Linear Algebra

Similar presentations


Presentation on theme: "Lecture 03: Linear Algebra"— Presentation transcript:

1 Lecture 03: Linear Algebra
COMP 175: Computer Graphics January 29, 2015

2 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 => = Matrix operations (multiplication, transpose, inverse, etc.)

3 Cartesian Coordinate System
1D, 2D, and 3D real coordinate spaces Compare this with positive integer coordinate spaces 1 2 3 4 5 -5 -4 -3 -1 -2 R 3 Z Y 1 2 3 4 5 -5 -4 -3 -1 -2 R 2 X Y 1 2 3 4 5 -5 -4 -3 -1 -2 R 1 1 2 3 4 5 1024 1 2 3 4 5 1024 “normal” coordinate axes computer screen axes 1024

4 Denotes a location in the Cartesian coordinate system
Points Denotes a location in the Cartesian coordinate system 1 2 3 4 5 -5 -4 -3 -1 -2 R 3 Z Y Point at (4, -2, 3) 1 2 3 4 5 -5 -4 -3 -1 -2 R 2 Point at (2, 3) X Y

5 Vectors Denotes: Magnitude Direction NO POSITION!! In ℝ 𝑑 , a vector can be defined as an ordered d-tuple: 𝑣= 𝑣 1 𝑣 2 ⋮ 𝑣 𝑑 A vector 𝑣 is often written as 𝑣 for clarity

6 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)

7 Vectors - Length Find the length of the following vector:

8 Vectors - Length the Euclidean length of a 2D vector 𝑣= 𝑣 𝑥 𝑣 𝑦 is:
𝑣 = 𝑣 𝑥 𝑣 𝑦 2 The length of a 𝑑-dimensional vector 𝑣= 𝑣 1 𝑣 2 ⋮ 𝑣 𝑑 is: 𝑣 = 𝑣 𝑣 𝑣 …+ 𝑣 𝑑 2 Note that the length of a vector is sometimes called the “norm” of the vector

9 Vectors – Scalar Multiple
For a vector 𝑣= 𝑣 1 𝑣 2 ⋮ 𝑣 𝑑 , the vector can be multiplied by a scalar value 𝛼 such that the resulting vector 𝑣′ is: 𝑣 ′ =𝛼𝑣=𝛼 𝑣 1 𝑣 2 ⋮ 𝑣 𝑑 = 𝛼 𝑣 1 𝛼 𝑣 2 ⋮ 𝛼 𝑣 𝑑 Question: what happens when 𝛼 is negative?

10 Vectors – Scalar Multiple
Examples of scalar multiples of the vector 𝑣= 5 1 These vectors are said to be parallel to the vector 𝑣. Question: What happens if 𝛼=0?

11 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: 𝑣 =1 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”.

12 Vectors – Unit Vector Question: Given a vector 𝑣, how do you find 𝑣 ?
Question: Can every vector be normalized? Question, what is the equation of a line using vector math? What about a point on the line? A range along the line (i.e. line segment)?

13 Addition of vectors is commutative (and associative). 𝑣= 2 3 , 𝑢= 4 2
Vectors - Addition Addition of vectors is commutative (and associative). 𝑣= , 𝑢= 4 2 6 7 8 9 10 1 2 3 5 4 v u 6 7 8 9 10 1 2 3 5 4 v u v + u

14 Addition of vectors is commutative (and associative).
Vectors - Addition Addition of vectors is commutative (and associative). 6 7 8 9 10 1 2 3 5 4 v u 6 7 8 9 10 1 2 3 5 4 v u u + v

15 Vectors – Addition Given two vectors, 𝑣= 2 3 , 𝑢= 4 2
6 7 8 9 10 1 2 3 5 4 v u v + u Given two vectors, 𝑣= , 𝑢= 4 2 𝑣+𝑢= = 6 5 Which is equal to: 𝑢+𝑣= = 6 5 6 7 8 9 10 1 2 3 5 4 v u u + v

16 Subtraction works the same as addition (with negative values):
Vectors - Subtraction Subtraction works the same as addition (with negative values): Given two vectors, 𝑣= , 𝑢= 4 2 𝑣−𝑢= − = −2 1 1 2 3 4 5 -4 -3 -2 -1 v u -u -4 -3 -2 -1 1 2 3 4 5 -u

17 Give two vectors 𝑢= 1 0 , and 𝑣= 0 1
Vectors – Basis Give two vectors 𝑢= , and 𝑣= 0 1 There are two interesting things about 𝑢, and 𝑣: They are perpendicular to each other They are both unit vectors 1.2 1.4 1.6 1.8 2 0.2 0.4 0.6 1 0.8 𝑣 𝑢

18 Vectors – Basis For 𝑢= 1 0 , and 𝑣= 0 1 :
1.2 1.4 1.6 1.8 2 0.2 0.4 0.6 1 0.8 𝑣 𝑢 Vectors – Basis For 𝑢= , and 𝑣= : They are perpendicular to each other (𝑢, and 𝑣 are said to be “orthogonal” to each other) They are both unit vectors 𝑥 𝑦 =𝑥𝑢+𝑦𝑣=𝑥 𝑦 0 1 These two vectors form the 2D Cartesian Coordinate System. We can say that 𝑢= and 𝑣= are the “basis vectors” of the 2D Cartesian Coordinate System

19 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

20 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 𝑢, 𝑣 6 7 8 9 10 1 2 3 5 4 𝑣 𝑤=1.5𝑣 +0.5𝑢 𝑢

21 Vector - Basis More formally, given a 2D vector 𝑤, we can express it using two basis vectors 𝑢 and 𝑣: 𝑤= 𝑛 𝑚 =𝑎𝑢+𝑏𝑣=𝑎 𝑢 1 𝑢 2 +𝑏 𝑣 1 𝑣 2 = 𝑎 𝑢 1 +𝑏 𝑣 1 𝑎 𝑢 2 +𝑏 𝑣 2 Question: Can you think of two vectors that CANNOT form basis vectors for a 2D space? (Hint: think linear independence)

22 Vector - Basis 𝑤= 𝑛 𝑚 =𝑎𝑢+𝑏𝑣=𝑎 𝑢 1 𝑢 2 +𝑏 𝑣 1 𝑣 2 = 𝑎 𝑢 1 +𝑏 𝑣 1 𝑎 𝑢 2 +𝑏 𝑣 2 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 OK not OK

23 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 𝒗, 𝟏∈ℝ, 𝟏∙𝒗=𝒗

24 Questions?

25 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 𝑣= 𝑣 1 𝑣 2 𝑣 3 and 𝑢= 𝑢 1 𝑢 2 𝑢 3 , the cross product is written as 𝑣×𝑢.

26 Vector – Cross Product Important Note: Cross Product is not commutative. That is: 𝑣×𝑢 ≠𝑢×𝑣 In fact, 𝑣×𝑢=−(𝑢×𝑣) The “Right Hand Rule”

27 Vector – Cross Product More formally: the cross product of 𝑣= 𝑣 𝑥 𝑣 𝑦 𝑣 𝑧 and 𝑢= 𝑢 𝑥 𝑢 𝑦 𝑢 𝑧 is written as: 𝑣×𝑢= 𝑣 𝑥 𝑣 𝑦 𝑣 𝑧 × 𝑢 𝑥 𝑢 𝑦 𝑢 𝑧 , and is defined as: 𝑣 𝑥 𝑣 𝑦 𝑣 𝑧 × 𝑢 𝑥 𝑢 𝑦 𝑢 𝑧 = 𝑣 𝑦 𝑢 𝑧 − 𝑣 𝑧 𝑢 𝑦 𝑣 𝑧 𝑢 𝑥 − 𝑣 𝑥 𝑢 𝑧 𝑣 𝑥 𝑢 𝑦 − 𝑣 𝑦 𝑢 𝑥

28 Vector – Cross Product In addition, it is important to note that:
𝑣×𝑢 ≠1 That is, the cross product of two vectors is not a normal vector (unless… (see below)). In fact, 𝑣×𝑢 = 𝑣 𝑢 sin 𝜃 where 𝜃 is the angle between the two vectors 𝑢 and 𝑣. What is the area of a parallelogram?

29 Vector – Cross Product If you think about it, this equation:
𝑣×𝑢 = 𝑣 𝑢 sin 𝜃 says that the magnitude of the cross product is “how perpendicular 𝑣 and 𝑢 are” Hint, think about the 𝜃. If 𝜃=90, then sin 𝜃 =1 Since the magnitude of a 3D vector is: 𝑣 = 𝑣 𝑥 𝑣 𝑦 𝑣 𝑧 2 We can think of the cross product as the “magnitude” of the sum of the x, y, and z components

30 Vector – Cross Product Deriving the cross product… For a simple 2D Case:

31 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.

32 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: 𝑎𝑟𝑒𝑎 (𝑦,𝑧) =( 𝐴 𝑦 𝐵 𝑧 − 𝐵 𝑦 𝐴 𝑧 ) 𝑥 𝑎𝑟𝑒𝑎 (𝑧,𝑥) =( 𝐴 𝑧 𝐵 𝑥 − 𝐵 𝑧 𝐴 𝑥 ) 𝑦

33 Vector – Cross Product 𝑎𝑟𝑒𝑎 (𝑥,𝑦) =( 𝐴 𝑥 𝐵 𝑦 − 𝐵 𝑥 𝐴 𝑦 ) 𝑧 𝑎𝑟𝑒𝑎 (𝑦,𝑧) =( 𝐴 𝑦 𝐵 𝑧 − 𝐵 𝑦 𝐴 𝑧 ) 𝑥 𝑎𝑟𝑒𝑎 (𝑧,𝑥) =( 𝐴 𝑧 𝐵 𝑥 − 𝐵 𝑧 𝐴 𝑥 ) 𝑦 Or more simply: 𝐴 𝑥 𝐴 𝑦 𝐴 𝑧 × 𝐵 𝑥 𝐵 𝑦 𝐵 𝑧 = 𝐴 𝑦 𝐵 𝑧 − 𝐴 𝑧 𝐵 𝑦 𝐴 𝑧 𝐵 𝑥 − 𝐴 𝑥 𝐵 𝑧 𝐴 𝑥 𝐵 𝑦 − 𝐴 𝑦 𝐵 𝑥

34 Vector – Cross Product Another way to derive the cross product:
Let’s say that we’re in ℝ 3 , 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: 𝑖×𝑖=𝑗×𝑗=𝑘×𝑘=0 𝑖×𝑗=𝑘, 𝑗×𝑘=𝑖, 𝑘×𝑖=𝑗 𝑗×𝑖=−𝑘, 𝑘×𝑗=−𝑖, 𝑖×𝑘=−𝑗

35 𝑣=( 𝑣 𝑥 𝑖+ 𝑣 𝑦 𝑗+ 𝑣 𝑧 𝑘), and 𝑢=( 𝑢 𝑥 𝑖+ 𝑢 𝑦 𝑗+ 𝑢 𝑧 𝑘)
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 𝑣×𝑢= 𝑣 𝑥 𝑖+ 𝑣 𝑦 𝑗+ 𝑣 𝑧 𝑘 × 𝑢 𝑥 𝑖+ 𝑢 𝑦 𝑗+ 𝑢 𝑧 𝑘 = 𝑣 𝑥 𝑢 𝑥 𝑖×𝑖+ 𝑣 𝑥 𝑢 𝑦 𝑖×𝑗+…= 𝑣 𝑦 𝑢 𝑧 − 𝑣 𝑧 𝑢 𝑦 𝑖+ 𝑣 𝑧 𝑢 𝑥 − 𝑣 𝑥 𝑢 𝑧 𝑗+ 𝑣 𝑥 𝑢 𝑦 − 𝑣 𝑦 𝑢 𝑥 𝑘

36 Vector – Cross Product One More Thought: For those of you who are ninja’s in linear algebra. You might have already noticed that: 𝑣×𝑢=det⁡ 𝑖 𝑗 𝑘 𝑣 𝑥 𝑣 𝑦 𝑣 𝑧 𝑢 𝑥 𝑢 𝑦 𝑢 𝑧 Recall that the determinant of a matrix is: 𝑣 𝑦 𝑢 𝑧 𝑖− 𝑣 𝑧 𝑢 𝑦 𝑖+ 𝑣 𝑧 𝑢 𝑥 𝑗− 𝑣 𝑥 𝑢 𝑧 𝑗+ 𝑣 𝑥 𝑢 𝑦 𝑘− 𝑣 𝑦 𝑢 𝑥 𝑘

37 Vector – Cross Product Recall that the determinant of a matrix is: 𝑣 𝑦 𝑢 𝑧 𝑖− 𝑣 𝑧 𝑢 𝑦 𝑖+ 𝑣 𝑧 𝑢 𝑥 𝑗− 𝑣 𝑥 𝑢 𝑧 𝑗+ 𝑣 𝑥 𝑢 𝑦 𝑘− 𝑣 𝑦 𝑢 𝑥 𝑘 Organize the terms a little bit, and you get: 𝑣 𝑥 𝑣 𝑦 𝑣 𝑧 × 𝑢 𝑥 𝑢 𝑦 𝑢 𝑧 = 𝑣 𝑦 𝑢 𝑧 − 𝑣 𝑧 𝑢 𝑦 𝑣 𝑧 𝑢 𝑥 − 𝑣 𝑥 𝑢 𝑧 𝑣 𝑥 𝑢 𝑦 − 𝑣 𝑦 𝑢 𝑥

38 Questions?

39 Vector – Dot Product Basic Formula: For two vectors, 𝑢 and 𝑣∈ ℝ 𝑑 , the dot product (or “inner product” or “scalar product”) is defined as: 𝑢∙𝑣= 𝑢 1 𝑣 1 + 𝑢 2 𝑣 2 +…+ 𝑢 𝑑 𝑣 𝑑 Or, 𝑢∙𝑣= 𝑖=1 𝑑 𝑢 𝑖 𝑣 𝑖

40 Vector – Dot Product As it turns out, if 𝑢 and 𝑣 are two non-zero vectors: 𝑢∙𝑣= 𝑢 𝑣 cos (𝜃) 𝑢 𝜃 𝑣

41 Vector – Dot Product This is important because if I want to know the angle between two vectors, I can trivially compute: 𝑢∙𝑣= 𝑢 𝑣 cos 𝜃 cos 𝜃 = 𝑢∙𝑣 𝑢 𝑣 𝜃= cos −1 ( 𝑢∙𝑣 𝑢 𝑣 ) Note that if both 𝑢 and 𝑣 are unit vectors, then: 𝜃= cos −1 (𝑢∙𝑣) Note that 𝜃 will be in radians (that is, 0≤𝜃≤𝜋)

42 Vector – Dot Product Other useful things with dot products What are the results?

43 Vector – Dot Product Other useful things with dot products

44 Determining “front” vs. “back” facing triangles
Vector – Dot Product Determining “front” vs. “back” facing triangles Back-face culling How to find the “normal vector”?

45 Vector – Dot Product Example: For 𝑢= 4 3 , and 𝑣= −3 4
Perpendicular vectors always have a dot product of 0 because the cosine of 90o is 0 For 𝑢= , and 𝑣= −3 4 𝑢∙𝑣= 4∙−3 + 3∙−4 =0 1 2 3 4 5 -5 -4 -3 -1 -2 𝑣 𝑢 𝑢∙𝑣= 𝑢 𝑣 cos ( 𝜋 2 ) =0

46 More use of the Dot Product: Finding the length of a projection
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 𝑢 v u 𝛼 𝜙 𝜃=(𝛼−𝜙) u’ Recall dot product: 𝑣∙𝑢=|𝑣||𝑢| cos 𝜃 If |𝑢| = 1, then 𝑣∙𝑢= 𝑣 cos 𝜃 =| 𝑢 ′ |

47 Vector – Dot Product Prove that: 𝑢∙𝑣= 𝑢 𝑣 cos 𝜃
𝑣= 𝑣 𝑥 𝑣 𝑦 = 𝑣 cos 𝛼 sin 𝛼 𝑢= 𝑢 𝑥 𝑢 𝑦 = 𝑢 cos 𝜙 sin 𝜙 𝑢∙𝑣= 𝑣 cos 𝛼 sin 𝛼 ∙ 𝑢 cos 𝜙 sin 𝜙 = 𝑣 𝑢 cos 𝛼 sin 𝛼 ∙ cos 𝜙 sin 𝜙 = 𝑣 𝑢 ( cos 𝛼 cos 𝜙 + sin 𝛼 sin 𝜙 ) By trigonometric identity: (see proof: proof.htm) cos 𝛼 cos 𝜙 + sin 𝛼 sin 𝜙 = cos (𝛼−𝜙) So, 𝑢∙𝑣= 𝑢 𝑣 cos 𝛼−𝜙 = 𝑢 𝑣 cos 𝜃 |v| sin() |v| cos() radius = ||v|| 𝜃=(𝛼−𝜙) 𝜙 𝛼 𝑣 𝑢

48 Questions?

49 Exercises: What is the result? A point 𝑝, a vector 𝑣, and a vector 𝑢, or a scalar 𝛼? 𝑣+𝑣=? 𝑝+𝑣=? 𝑝−𝑝=? 𝑝+𝑝=? 𝑣×𝑢=? 𝑣×𝑣=? 𝑣∙𝑢=? 𝑣∙𝑣=? Show that 𝑣×𝑢 is orthogonal to both 𝑣 and 𝑢 Hint: how to test if two vectors are orthogonal?

50 Questions?


Download ppt "Lecture 03: Linear Algebra"

Similar presentations


Ads by Google