vectors - clemson universitydhouse/courses/405/notes/vectors.pdfchapter 1 vectors to the left are...

9
Chapter 1 Vectors To the left are three visual representations of the same vec- tor. What is a vector? It is simply a way of storing and handling two pieces of information: 1. a direction in space, and 2. a magnitude. An arrow is a convenient way to draw a vector; since both length and direction are clearly indicated. The arrows to the left represent identical vectors, since they have the same length and are parallel to each other. In the study of computer graphics, we will mainly be interested in vectors in two-dimensional (2D) and in three- dimensional (3D) space, but vectors can be defined in a space of any number of dimensions. Algebraically, a vector is usually denoted by a low-case letter, which has a line over it, like v, or is printed in bold type, like v. For hand written notes, the line is most convenient, but in printed form the bold form is more usual. Throughout these notes the v form will be used. A vector in 2D space is defined by a pair of scalars arranged in a column, like v = v x v y . When working in 2D, the direction of the vector is given by the slope m = v y /v x , and the length by kvk = q v 2 x + v 2 y . A vector in 3D space is defined by three scalars arranged in a column, like v = v x v y v z . In 3D there is no simple equivalent to the slope. It turns out that the direction of a 3D vector is best understood by first converting it to a unit vector, which is discussed 1

Upload: buinhi

Post on 04-May-2018

217 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Vectors - Clemson Universitydhouse/courses/405/notes/vectors.pdfChapter 1 Vectors To the left are three visual representations of the same vec-tor. What is a vector? It is simply a

Chapter 1

Vectors

To the left are three visual representations of the same vec-tor. What is a vector? It is simply a way of storing andhandling two pieces of information:

1. a direction in space, and

2. a magnitude.

An arrow is a convenient way to draw a vector; since bothlength and direction are clearly indicated. The arrows tothe left represent identical vectors, since they have the same

length and are parallel to each other. In the study of computer graphics,we will mainly be interested in vectors in two-dimensional (2D) and in three-dimensional (3D) space, but vectors can be defined in a space of any numberof dimensions.

Algebraically, a vector is usually denoted by a low-case letter, which has a lineover it, like v, or is printed in bold type, like v. For hand written notes, the lineis most convenient, but in printed form the bold form is more usual. Throughoutthese notes the v form will be used.

A vector in 2D space is defined by a pair of scalars arranged in a column, like

v =[vx

vy

]. When working in 2D, the direction of the vector is given by the

slope m = vy/vx, and the length by ‖v‖ =√v2

x + v2y. A vector in 3D space is

defined by three scalars arranged in a column, like v =

vx

vy

vz

. In 3D there is

no simple equivalent to the slope. It turns out that the direction of a 3D vectoris best understood by first converting it to a unit vector, which is discussed

1

Page 2: Vectors - Clemson Universitydhouse/courses/405/notes/vectors.pdfChapter 1 Vectors To the left are three visual representations of the same vec-tor. What is a vector? It is simply a

2 CHAPTER 1. VECTORS

below. The length of a 3D vector is given by ‖v‖ =√v2

x + v2y + v2

z .

1.1 Unit or Direction vectors

v

uv

The direction of a vector in any dimensional space is most eas-ily defined by a unit vector, also called a direction vector, thatis parallel to the vector. A unit vector, for a particular vec-tor, is simply that vector scaled so that it has unit magnitude.Throughout these notes we will use the bold letter u to indi-cate a unit vector, with a subscript corresponding to the vectorthat it is parallel to. For example, the unit or direction vectorcorresponding with the 2D vector v would be

uv =[ux

uy

]=[vx/‖v‖vy/‖v‖

].

An interpretation of a direction vector would be as follows. Start from any pointp in space. The unit vector determines the position p′ you would reach travelingone unit of distance in the direction of the vector. For example, suppose thatwe start at point p in the figure below and follow the direction vector uv. If wemove one unit of distance along the direction of the vector, the x component ofour position will be incremented by ux and the y component by uy.

(1)

p

p'

End here

Start here

Trave

l 1 un

it of

Distan

ce al

ong v

uv

v

Page 3: Vectors - Clemson Universitydhouse/courses/405/notes/vectors.pdfChapter 1 Vectors To the left are three visual representations of the same vec-tor. What is a vector? It is simply a

1.2. VECTOR ADDITION 3

1.2 Vector addition

aa+b

bAddition of vectors can be expressed by a diagram. Plac-ing the vectors end to end, the vector from the start of thefirst vector to the end of the second vector is the sum ofthe vectors. Algebraically, this is equivalent to adding cor-responding terms of the two vectors:

a + b =[ax

ay

]+[bxby

]=[ax + bxay + by

].

1.3 Points and vectors

(0,0)

(x,y)

Y p

O

pX

This leads us to the idea that a point can be used todefine a vector. If we have point p = (x, y), this defines

vector p =[xy

], which determines the distance and

direction from the origin O of the space to the point p.So we can write

p′ = p + uv,

as an algebraic way of representing the figure above la-beled (1).

1.4 Vector subtraction

b a

a - bSubtraction of vectors can be shown in diagram form by plac-ing the starting points of the two vectors together, and thenconstructing an arrow from the head of the second vector inthe subtraction to the head of the first vector. Algebraically,we subtract corresponding terms:

a− b =[ax

ay

]−[bxby

]=[ax − bxay − by

].

Page 4: Vectors - Clemson Universitydhouse/courses/405/notes/vectors.pdfChapter 1 Vectors To the left are three visual representations of the same vec-tor. What is a vector? It is simply a

4 CHAPTER 1. VECTORS

1.5 Scaling a vector

a

2a

a/2

Multiplication of a vector by a scalar leaves the vec-tor’s direction unchanged, but multiplies its magnitudeby the scalar. Algebraically, we multiply each term ofthe vector by the scalar. For example

2a = 2[ax

ay

]=[

2ax

2ay

].

Division by a scalar is the same as multiplication by thereciprocal of the scalar:

a/2 =[ax/2ay/2

].

1.6 Dot or inner product

Vector-vector multiplication is not as easily defined as addition, subtractionand scalar multiplication. There are actually several vector products that canbe defined. First, we will look at the dot product of two vectors, which is oftencalled their inner product.

Defined algebraically, the dot product of two vectors and is given by

a · b =[ax

ay

]·[bxby

]= axbx + ayby.

We multiply corresponding terms and add the result. The result is not a vector,but is in fact a scalar. This turns out to have many ramifications. The dotproduct is a mighty operation and has many uses, particularly in graphics!

1.6.1 Trigonometric interpretation of dot product

blIa

II IIbIl c

os

a

The dot product can be written in trigonometricform as

a · b = ‖a‖‖b‖ cos θ,

where θ is the smallest angle between the two vec-tors. Note that if both a and b are unit vectors,then ‖a‖‖b‖ = 1, and a · b = cos θ. So, in general

Page 5: Vectors - Clemson Universitydhouse/courses/405/notes/vectors.pdfChapter 1 Vectors To the left are three visual representations of the same vec-tor. What is a vector? It is simply a

1.6. DOT OR INNER PRODUCT 5

if you want to find the angle between two vectors aand b, first compute the unit vectors ua and ub inthe directions of a and b then

cos θ = ua · ub.

Other things to note about the trigonometric representation of dot product arethat

1. the dot product of orthogonal (perpendicular) vectors is zero, so if a·b = 0we know that either one of the vectors is of zero length or the vectors areorthogonal,

2. the dot product of two vectors is negative if the smallest angle betweenthe vectors exceeds 90◦, and is positive otherwise.

1.6.2 Geometric interpretation of dot product

a

uab

u a• b

Another very useful interpretation of the dot prod-uct is that it can be used to compute the componentof one vector in the direction parallel to another vec-tor. For example, let ua be a unit vector in thedirection of vector a. Then the length of the projec-tion of another vector b in the direction of a vectora is ua · b. You can think of this as the length ofthe shadow of vector b on vector a. Therefore, thevector component of b in the direction of a is

ba = (ua · b)ua.

So, ba is parallel to a and has length equal to the projection of b onto a. Notealso that b− ba will be the component of b perpendicular to vector a.

The dot product has many uses in graphics, which the following two exampleswill serve to illustrate.

Page 6: Vectors - Clemson Universitydhouse/courses/405/notes/vectors.pdfChapter 1 Vectors To the left are three visual representations of the same vec-tor. What is a vector? It is simply a

6 CHAPTER 1. VECTORS

1.6.3 Dot product example: The distance from a point toa line

a

bx

p

baua

Let us look at how dot product can be used to com-pute an important geometric quantity: the distanceof a point from a line. Note that a single point and avector uniquely define a line through the point andparallel to the vector. Let p be any point on the lineand let a be a vector parallel to the line, and defineua to be the unit vector in the direction of vectora. Now we will see how to compute the distance ofany arbitrary point x from the line defined by pointp and vector a. Let b = x − p be the vector fromthe known point on the line to point x. Now thecomponent of b in the direction of vector a is

ba = (ua · b)ua.

Thus, the component of b perpendicular to a is

b⊥ = b− ba,

and the distance of point x from the line is the magnitude ‖b⊥‖ of this per-pendicular vector.

1.6.4 Dot product example: Mirror reflection

vn

vr

Another very useful example of the use of dot prod-uct in geometric calculations is the computation ofthe mirror reflection from a surface. Assume thatwe have a flat mirror surface whose surface normalis the unit vector n. The surface normal is definedto be a unit vector whose direction is perpendicularto the surface. Now, we shine a light ray with direc-tion v at the surface. The direction of the reflectedray will be given by vr. What must be true is thatthe angle θ between the normal n and the light rayv should be the same as the angle between the re-

flected ray and the normal, and all three vectors v, n, and vr must lie in thesame plane. Given these constraints, below is one way to calculate the lightreflection ray vr.

Page 7: Vectors - Clemson Universitydhouse/courses/405/notes/vectors.pdfChapter 1 Vectors To the left are three visual representations of the same vec-tor. What is a vector? It is simply a

1.7. CROSS PRODUCT 7

b

vr

b

n v

v

Examining the figure to the left, we first rotate thescene so we have everything in a convenient orienta-tion, with the surface normal n pointing vertically,and the surface horizontal. Now, move vector v sothat its tail is at the reflection point, as shown bythe vector drawn with a dashed line in the figure. Ifb is the vector parallel to n from the head of v tothe surface, then by vector addition we have

vr = v + 2b.

Now the vector b is just the negative of the compo-nent of v in the direction of n. So,

b = −(n · v)n.

Thus,vr = v − 2(n · v)n.

1.7 Cross Product

a bxb

a

The cross product a× b between two vectors a andb is a new vector perpendicular to the plane definedby the original two vectors. The figure to the left il-lustrates the construction. In other words, the crossproduct of two vectors is a vector that is perpendic-ular to both of the original vectors.

This notion of cross product does not make sense in 2D space, since it is notpossible for a third 2D vector to be perpendicular to two (non parallel) 2Dvectors. Thus, in graphics, the notion of cross product is reserved for workingin 3D space.

The direction of the cross product vector follows the right-hand rule. Hold yourright hand out flat, and align the fingers so they point in the direction of a.Now, curl the fingers of your right hand from vector a to vector b. Your thumbwill point in the direction of a × b. If you reverse this, and first align yourfingers with b and then curl them towards a you will see that you have to turnyour hand upside down, reversing the direction in which your thumb is pointing.From this it should be apparent that b × a = −(a × b). In other words, theorder of the operands in the cross product changes the polarity of the resultingcross product vector. The result is still perpendicular to both of the originalvectors, but the direction is flipped.

Page 8: Vectors - Clemson Universitydhouse/courses/405/notes/vectors.pdfChapter 1 Vectors To the left are three visual representations of the same vec-tor. What is a vector? It is simply a

8 CHAPTER 1. VECTORS

The magnitude of the cross product is given by

‖a× b‖ = ‖a‖‖b‖| sin θ|,

where θ is the small angle between vectors a and b. Thus, if a and b are unitvectors, the magnitude of the cross product is the magnitude of sin θ.

Note, that the cross product of two parallel vectors will be the zero vector 0.This is consistent with the geometric notion that the cross product produces avector orthogonal to the original two vectors. If the original vectors are parallel,then there is no unique direction perpendicular to both vectors (i.e. there areinfinitely many orthogonal vectors, all parallel to any plane perpendicular toeither vector).

Algebraically, if

a =

ax

ay

az

, and b =

bxbybz

,then

a× b =

aybz − azbyazbx − axbzaxby − aybx

.

The cross product has many uses in graphics, which the following two exampleswill serve to illustrate.

1.7.1 Cross product example: Finding surface normals

p2

p0

p1v02

v01

n

Suppose we have triangle (p0,p1,p2), and we wantto find the triangle’s surface normal. We can easilyfind it by use of a cross product operation. First,define vectors v01 = p1 − p0, and v02 = p2 − p0.Then the cross product v01×v02 is a vector perpen-dicular to both v01 and v02, and thus perpendicularto the plane of the triangle. Thus, the unit surfacenormal vector to the triangle is given by

n = (v01 × v02)/‖v01 × v02‖.

Page 9: Vectors - Clemson Universitydhouse/courses/405/notes/vectors.pdfChapter 1 Vectors To the left are three visual representations of the same vec-tor. What is a vector? It is simply a

1.7. CROSS PRODUCT 9

1.7.2 Cross product example: Creating a local coordinateframe

v1v0

Suppose we have two vectors v0 and v1, that wewould like to use to create a unique 3D coordinateframe (i.e. three orthogonal directions in space).To describe this coordinate frame, we would liketo create three mutually perpendicular unit vectorsux,uy, and uz, aligned with the three coordinateaxes of the space.

uy

v1v0

ux

uz

We can arbitrarily pick the x axis direction to bealigned with v0, so

ux = v0/‖v0‖.

We know that the cross product between v0 and v1

will be perpendicular to both vectors, so let us saythat this aligns with the z axis, giving

uz = (v0 × v1)/‖v0 × v1‖.

The third, or y axis must be perpendicular to both ux and uy, so

uy = uz × ux,

which is guaranteed to be a unit vector since both ux and uz are unit vectors,and the angle between them is 90◦ (i.e. sin 90◦ = 1).