Vector Math Computer Graphics Scott D. Anderson



Similar documents
Adding vectors We can do arithmetic with vectors. We ll start with vector addition and related operations. Suppose you have two vectors

Vectors Math 122 Calculus III D Joyce, Fall 2012

Figure 1.1 Vector A and Vector F

v 1 v 3 u v = (( 1)4 (3)2, [1(4) ( 2)2], 1(3) ( 2)( 1)) = ( 10, 8, 1) (d) u (v w) = (u w)v (u v)w (Relationship between dot and cross product)

Section V.3: Dot Product

5.3 The Cross Product in R 3

A vector is a directed line segment used to represent a vector quantity.

9 Multiplication of Vectors: The Scalar or Dot Product

28 CHAPTER 1. VECTORS AND THE GEOMETRY OF SPACE. v x. u y v z u z v y u y u z. v y v z

9.4. The Scalar Product. Introduction. Prerequisites. Learning Style. Learning Outcomes

Section 1.1. Introduction to R n

One advantage of this algebraic approach is that we can write down

13.4 THE CROSS PRODUCT

Cross product and determinants (Sect. 12.4) Two main ways to introduce the cross product

Lecture L3 - Vectors, Matrices and Coordinate Transformations

Math 241, Exam 1 Information.

Review A: Vector Analysis

v w is orthogonal to both v and w. the three vectors v, w and v w form a right-handed set of vectors.

AP Physics - Vector Algrebra Tutorial

Dot product and vector projections (Sect. 12.3) There are two main ways to introduce the dot product

Math 215 HW #6 Solutions

The Vector or Cross Product

Unified Lecture # 4 Vectors

[1] Diagonal factorization

Biggar High School Mathematics Department. National 5 Learning Intentions & Success Criteria: Assessing My Progress

Vector has a magnitude and a direction. Scalar has a magnitude

Orthogonal Projections

Inner Product Spaces

Chapter 17. Orthogonal Matrices and Symmetries of Space

x1 x 2 x 3 y 1 y 2 y 3 x 1 y 2 x 2 y 1 0.

Physics 235 Chapter 1. Chapter 1 Matrices, Vectors, and Vector Calculus

Geometric description of the cross product of the vectors u and v. The cross product of two vectors is a vector! u x v is perpendicular to u and v

Recall that two vectors in are perpendicular or orthogonal provided that their dot

Higher Education Math Placement

The Dot and Cross Products

Equations Involving Lines and Planes Standard equations for lines in space

1.3. DOT PRODUCT If θ is the angle (between 0 and π) between two non-zero vectors u and v,

The Force Table Introduction: Theory:

Section 10.4 Vectors

Lectures notes on orthogonal matrices (with exercises) Linear Algebra II - Spring 2004 by D. Klain

Lecture 14: Section 3.3

Vector Algebra CHAPTER 13. Ü13.1. Basic Concepts

Algebra and Geometry Review (61 topics, no due date)

PHYSICS 151 Notes for Online Lecture #6

α = u v. In other words, Orthogonal Projection

Chapter 3 Vectors. m = m1 + m2 = 3 kg + 4 kg = 7 kg (3.1)

6. Vectors Scott Surgent (surgent@asu.edu)

Linear Algebra Notes for Marsden and Tromba Vector Calculus

13 MATH FACTS a = The elements of a vector have a graphical interpretation, which is particularly easy to see in two or three dimensions.

Vectors 2. The METRIC Project, Imperial College. Imperial College of Science Technology and Medicine, 1996.

11.1. Objectives. Component Form of a Vector. Component Form of a Vector. Component Form of a Vector. Vectors and the Geometry of Space

Vectors and Scalars. AP Physics B

FURTHER VECTORS (MEI)

Evaluating trigonometric functions

Thnkwell s Homeschool Precalculus Course Lesson Plan: 36 weeks

MATH2210 Notebook 1 Fall Semester 2016/ MATH2210 Notebook Solving Systems of Linear Equations... 3

2.2 Magic with complex exponentials

The Geometry of the Dot and Cross Products

The Geometry of the Dot and Cross Products

Solutions to old Exam 1 problems

Solutions to Practice Problems

MAT 1341: REVIEW II SANGHOON BAEK

Geometry of Vectors. 1 Cartesian Coordinates. Carlo Tomasi

ex) What is the component form of the vector shown in the picture above?

Solving Simultaneous Equations and Matrices

Similarity and Diagonalization. Similar Matrices

Mechanics 1: Vectors

3. INNER PRODUCT SPACES

VECTOR ALGEBRA A quantity that has magnitude as well as direction is called a vector. is given by a and is represented by a.

Notes on Orthogonal and Symmetric Matrices MENU, Winter 2013

Rotation Matrices and Homogeneous Transformations

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS. + + x 2. x n. a 11 a 12 a 1n b 1 a 21 a 22 a 2n b 2 a 31 a 32 a 3n b 3. a m1 a m2 a mn b m

Linear algebra and the geometry of quadratic equations. Similarity transformations and orthogonal matrices

Trigonometry for AC circuits

Solutions to Math 51 First Exam January 29, 2015

Exam 1 Sample Question SOLUTIONS. y = 2x

Numerical Analysis Lecture Notes

Introduction Assignment

South Carolina College- and Career-Ready (SCCCR) Pre-Calculus

Right Triangles A right triangle, as the one shown in Figure 5, is a triangle that has one angle measuring

Correlation and Convolution Class Notes for CMSC 426, Fall 2005 David Jacobs

2x + y = 3. Since the second equation is precisely the same as the first equation, it is enough to find x and y satisfying the system

Parallel and Perpendicular. We show a small box in one of the angles to show that the lines are perpendicular.

National 5 Mathematics Course Assessment Specification (C747 75)

THREE DIMENSIONAL GEOMETRY

Additional Topics in Math

Trigonometric Functions and Triangles

EDEXCEL NATIONAL CERTIFICATE/DIPLOMA MECHANICAL PRINCIPLES AND APPLICATIONS NQF LEVEL 3 OUTCOME 1 - LOADING SYSTEMS

TWO-DIMENSIONAL TRANSFORMATION

Solutions to Exercises, Section 5.1

x = + x 2 + x

Unit 11 Additional Topics in Trigonometry - Classwork

Chapter 6. Linear Transformation. 6.1 Intro. to Linear Transformation

WHEN DOES A CROSS PRODUCT ON R n EXIST?

Addition and Subtraction of Vectors

Two vectors are equal if they have the same length and direction. They do not

Definition: A vector is a directed line segment that has and. Each vector has an initial point and a terminal point.

Linearly Independent Sets and Linearly Dependent Sets

Inner product. Definition of inner product

Transcription:

Vector Math Computer Graphics Scott D. Anderson 1 Dot Product The notation v w means the dot product or scalar product or inner product of two vectors, v and w. In abstract mathematics, we can talk about choosing an inner product on a vector space, and that inner product has to satisfy certain properties: v w R That is, the dot product of two vectors is just a real number, a scalar (not a vector). v,v v 0 iff v 0. That is, the dot product of a vector with itself is zero if and only if the vector is the zero vector. In 3D, the zero vector is (0,0,0). (commutativity) v w w v. That is, the order of the vectors doesn t matter. (linearity) v (au + bw) a(u v) + b(v w). That is, the dot product of a vector v with the linear combination of two other vectors, u and w, is the same as the linear combination of the two dot products. But in this course, we re going to be very concrete. We will define the dot product as the sum of products: n v w v i w i i0 In fact, since we only are using 3 dimensions, x, y and z: v w v x w x + v y w y + v z w z You can easily check that this definition of a dot product satisfies the required properties. Note that calculating one element of a matrix multiplication is the same thing as a dot product: the result element is the dot product of a row from the first matrix with a column from the second matrix. 1.1 Example Suppose we have the following two vectors: v (1,2,3) w (6,5,4) The dot product of those vectors is: v w 1 6 + 2 5 + 3 4 6 + 10 + 12 28 Note that the dot product of two vectors is a scalar: a real number, not a vector. 1

2 Length Given the dot product, we can define the length of a vector: v v v This is just our old friend the Pythagorean theorem in disguise! Why? Because the dot product of a vector with itself ends up squaring each element and adding them up. Note that we can rescale (shrink or grow) any vector (except the zero vector) to have unit length. This is called normalizing. w v v w 1 The result is called a unit vector. We often will use unit vectors in computer graphics. For example, normal vectors (vectors perpendicular to a surface) are usually specified as unit vectors. See the last section, below. 2.1 Example What is the length of the vector v (2, 3, 6)? v 2 2 + 3 2 + 6 2 4 + 9 + 36 49 7 If we normalize v, what do we get? Let w v/ v, we get w (2,3,6)/7 (2/7,3/7,6/7) (0.28,0.43,0.86) You can easily check that w 1. The vector w is in exactly the same direction as v, but it s one unit long. 3 Angles Between Vectors The angle between two vectors v and w can be found using the following formula. Amazing, but true. cos(θ) v w which I like to also think of as: cos(θ) v v w w In other words, it s just the dot product of the two unit vectors. That is, if both of two vectors v and w are normalized (a length of one unit), the formula for the cosine of the angle between them becomes the following, which is remarkably simple: cos(θ) v w This is good news, because a dot product is very quick to compute: in 3D, it s just 3 multiplies and 2 adds. It turns out that the cosine of an angle is often desired in computer graphics, so being able to compute it so simply is enormously valuable. In fact, there are occasions when the tail wags the dog: the cosine of the angle is used because it s so quick to compute. It s used a lot in lighting calculations. 2

3.1 Example 1 Given the following vectors, what is the cosine of the angle between them? v (2,3,6) w (9,6,2) Since we already know the length of v, let s first find the length of w: w w w 9 2 + 6 2 + 2 2 81 + 36 + 4 121 11 Therefore, the cosine of the angle between v and w is: cos(θ) v w 7 11 2 9 + 3 6 + 6 2 18 + 18 + 12 48 77 77 77 0.62 If, for some reason, we needed the actual angle, we could compute the arc cosine, but we ll almost never need that. (This angle is about 51 degrees.) 3.2 Example 2 Suppose we have the vectors x (1,0,0) and y (0,1,0). That is, these are unit vectors that point in the direction of the X and Y axes. It s easy to see that the dot product between these is zero. What does this mean? If the cosine of an angle is zero, that means the angle is a right angle (ninety degrees). That is, these two vectors are perpendicular. (We re not surprised that they re perpendicular, but it s nice to see that the calculation confirms it.) In linear algebra, the term orthogonal is used for vectors that are perpendicular. In geek-speak, we say that two things are orthogonal if one doesn t affect the other. This makes sense because we can translate an object by multiples of the vector x without affecting its Y coordinate, and translate it by multiples of the vector y without affecting its X coordinate. 3.3 Example 3 What can we say about the angle, θ between the vectors: v (2,3,6) u ( 6, 10, 3) The cosine of the angle is found by: cos(θ) (2,3,6) ( 6,10, 3) v u 12 + 30 18 v u 0 v u 0 So, these vectors are perpendicular (orthogonal). 3

4 Applying the Law of Cosines This section proves that the dot product of normalized vectors is the angle between them. You can skip it if you re not interested. W V W V According to the law of cosines, from trigonometry: v w 2 v 2 + w 2 2cos(θ) Where θ is the angle between v and w. With some algebra, we get: All the terms in v w are of the form multiplying out to cos(θ) v 2 + w 2 v w 2 2 (v 0 w 0 ) 2 v 2 0 2v 0 w 0 + w 2 0 That means that all the squared terms in the numerator disappear, the 2 cancels with the denominator, and we are left only with the cross terms: cos(θ) ni0 v i w i but that numerator is just the dot product of v and w, so cos(θ) v w 4

5 Cross Product As we know, the dot product of two vectors produces a scalar. The cross product produces a vector: one that is perpendicular to both of them. In 3D, the cross product is: n v w v x v y v z w x w y w z v y w z v z w y v z w x v x w z v x w y v y w x Note that order matters: v w w v. Notice also that in computing n x, you use only terms from the Y and Z components, and similarly for n y and n z. There s a nice graphical way to remember the way to compute this. Looking at the following figures, multiply the terms connected by lines, and subtract one line from another. For the X and Z, you subtract the major diagonal (sloping down to the right) from the minor diagonal, and for Y, you subtract them in the opposite order (or just negate the result). nx vx wx ny vy x wy nz vz wz nx vx wx ny vy x wy nz vz wz nx vx wx ny vy x wy nz vz wz 5.1 Direction of the cross product What direction does the vector go in? For that, we need the right-hand rule: point the fingers of your right hand in the direction of the first vector, sweep them towards the second, and your thumb points in the direction of the cross product. Alternatively, point your thumb in the direction of the first vector, your index in the direction of the second, and your middle finger in the direction of the cross-product. Interestingly, z x y, x y z and y z x. That is, a normalized vector parallel to the z axis, (0,0,1) is the cross product of vectors for the x axis, (1,0,0), and the y axis, (0,1,1). 5.2 Length of the cross product The length of the cross-product divided by the lengths of the two vectors gives the sine of the angle between the two vectors: 5.3 Example sin(θ) Find the cross product of the following two vectors: v w v (2,3,6) w (9,6,2) 5

We ll write the vectors vertically in order to find the result. n v w 2 3 6 9 6 2 3 2 6 6 9 6 2 2 2 6 9 3 6 36 54 4 12 27 30 50 15 We already know from previous examples that v 7 and w 11. The sine of the angle between v and w is sin(θ) n 900 + 2500 + 225 3625 0.78 77 77 Earlier, in section 3.1, we found that the cosine of the angle between v and w is 48/77. Therefore, we should be able to confirm that: Whew! 1 cos 2 (θ) + sin 2 (θ) (48/77) 2 + ( 3625/77) 2 (2304 + 3625)/77 2 5929/5929 5.4 Normal Vectors A vector that is perpendicular to a surface, such as a plane or a sphere, is said to be normal to it. It s therefore called a normal vector. (Other vectors are not abnormal.) Normal vectors for surfaces are crucial in lighting calculations, because the normal vector tells us the orientation of the surface, and the orientation is important to how light falls on the surface and where it reflects to. A common way to find a normal vector for plane is to find two vectors that lie in the plane and take their cross product. To find a normal vector for a surface, find a plane that is tangent at the desired point, and find the normal vector for that plane. We ll see examples of this later in the course. You ll want to convert that normal vector to unit length when specifying the surface normal in OpenGL. However, a hidden pitfall is that if you scale the coordinate system, these normal vectors will get scaled as well, and no longer have unit length, which is why in OpenGL there is a setting glenable(gl NORMALIZE) telling the software to normalize the normal vectors, thereby using the word normal in two different ways in the same sentence. 6