3
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2016 Tamara Munzner http://www.ugrad.cs.ubc.ca/~cs314/Vjan2016 Math Basics Week 1, Fri Jan 8 2 Readings For Lecture Shirley/Marschner (3 rd edition) Ch 2: Miscellaneous Math, Sec 2.1-2.4 Ch 5: Linear Algebra, Sec 5.1-5.3 Gortler Ch 2: Linear, Sec 2.1 – 2.4 Vectors and Matrices 3 4 Notation: Scalars, Vectors, Matrices scalar (lower case, italic) vector (lower case, bold) matrix (upper case, bold) a [ ] n a a a ... 2 1 = a ! ! ! " # $ $ $ % & = 33 32 31 23 22 21 13 12 11 a a a a a a a a a A 5 Vectors arrow: length and direction oriented segment in nD space offset / displacement location if given origin 6 Column vs. Row Vectors row vectors column vectors switch back and forth with transpose ! ! ! ! " # $ $ $ $ % & = n col a a a ... 2 1 a row T col a a = [ ] n row a a a ... 2 1 = a 7 Vector-Vector Addition add: vector + vector = vector parallelogram rule tail to head, complete the triangle ! ! ! " # $ $ $ % & + + + = + 3 3 2 2 1 1 v u v u v u v u ) 0 , 6 , 5 ( ) 1 , 1 , 3 ( ) 1 , 5 , 2 ( ) 6 , 9 ( ) 4 , 6 ( ) 2 , 3 ( = + = + v u + u v geometric algebraic examples: 8 Vector-Vector Subtraction subtract: vector - vector = vector ! ! ! " # $ $ $ % & = 3 3 2 2 1 1 v u v u v u v u ) 2 , 4 , 1 ( ) 1 , 1 , 3 ( ) 1 , 5 , 2 ( ) 2 , 3 ( ) 4 , 6 ( ) 2 , 3 ( = = = v u u v v ) ( v u + 9 Vector-Vector Subtraction subtract: vector - vector = vector ! ! ! " # $ $ $ % & = 3 3 2 2 1 1 v u v u v u v u ) 2 , 4 , 1 ( ) 1 , 1 , 3 ( ) 1 , 5 , 2 ( ) 2 , 3 ( ) 4 , 6 ( ) 2 , 3 ( = = = v u u v v ) ( v u + v u + v u u v v u argument reversal 10 Scalar-Vector Multiplication multiply: scalar * vector = vector vector is scaled ) * , * , * ( * 3 2 1 u a u a u a a = u ) 5 ,. 5 . 2 , 1 ( ) 1 , 5 , 2 ( * 5 . ) 4 , 6 ( ) 2 , 3 ( * 2 = = u * a u 11 Vector-Vector Multiplication: Dot multiply v1: vector * vector = scalar dot product, aka inner product v u ( )( )( ) 3 3 2 2 1 1 3 2 1 3 2 1 v u v u v u v v v u u u + + = " " " # $ % % % & ' " " " # $ % % % & ' 12 Vector-Vector Multiplication: Dot multiply v1: vector * vector = scalar dot product, aka inner product v u ( )( )( ) 3 3 2 2 1 1 3 2 1 3 2 1 v u v u v u v v v u u u + + = " " " # $ % % % & ' " " " # $ % % % & ' ( )( )( ) 3 3 2 2 1 1 3 2 1 3 2 1 v u v u v u v v v u u u + + = " " " # $ % % % & ' " " " # $ % % % & ' 13 Vector-Vector Multiplication: Dot multiply v1: vector * vector = scalar dot product, aka inner product u 1 u 2 u 3 " # $ $ $ % & ' ' ' v 1 v 2 v 3 " # $ $ $ % & ' ' ' = u 1 v 1 ( ) + u 2 v 2 ( ) + u 3 v 3 ( ) v u θ cos v u v u = u v θ geometric interpretation lengths, angles can find angle between two vectors 14 Dot Product Geometry can find length of projection of u onto v as lines become perpendicular, θ cos v u v u = u v θ θ cos u 0 v u v v u u = θ cos 15 Dot Product Example 19 6 7 6 ) 3 * 2 ( ) 7 * 1 ( ) 1 * 6 ( 3 7 1 2 1 6 = + + = + + = ! ! ! " # $ $ $ % & ! ! ! " # $ $ $ % & u 1 u 2 u 3 " # $ $ $ % & ' ' ' v 1 v 2 v 3 " # $ $ $ % & ' ' ' = u 1 v 1 ( ) + u 2 v 2 ( ) + u 3 v 3 ( ) 16 Vector-Vector Multiplication, Cross multiply v2: vector * vector = vector cross product algebraic ! ! ! " # $ $ $ % & = ! ! ! " # $ $ $ % & × ! ! ! " # $ $ $ % & 1 2 2 1 3 1 1 3 2 3 3 2 3 2 1 3 2 1 v u v u v u v u v u v u v v v u u u

Vectors Column vs. Row Vectors Vector-Vector Addition ... · Math Basics Week 1, Fri Jan 8 2 Readings For Lecture ¥!Shirley/ Marschner (3rd edition) ... right hand rule: index finger

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Vectors Column vs. Row Vectors Vector-Vector Addition ... · Math Basics Week 1, Fri Jan 8 2 Readings For Lecture ¥!Shirley/ Marschner (3rd edition) ... right hand rule: index finger

University of British Columbia CPSC 314 Computer Graphics

Jan-Apr 2016

Tamara Munzner

http://www.ugrad.cs.ubc.ca/~cs314/Vjan2016

Math Basics

Week 1, Fri Jan 8

2

Readings For Lecture

•  Shirley/Marschner (3rd edition) •  Ch 2: Miscellaneous Math, Sec 2.1-2.4 •  Ch 5: Linear Algebra, Sec 5.1-5.3

•  Gortler

•  Ch 2: Linear, Sec 2.1 – 2.4

Vectors and Matrices

3 4

Notation: Scalars, Vectors, Matrices •  scalar

•  (lower case, italic) •  vector

•  (lower case, bold) •  matrix

•  (upper case, bold)

a

[ ]naaa ...21=a

!!!

"

#

$$$

%

&

=

333231

232221

131211

aaaaaaaaa

A

5

Vectors

•  arrow: length and direction •  oriented segment in nD space

•  offset / displacement •  location if given origin

6

Column vs. Row Vectors •  row vectors

•  column vectors

•  switch back and forth with transpose

!!!!

"

#

$$$$

%

&

=

n

col

a

aa

...2

1

a

rowTcol aa =

[ ]nrow aaa ...21=a

7

Vector-Vector Addition •  add: vector + vector = vector •  parallelogram rule

•  tail to head, complete the triangle

!!!

"

#

$$$

%

&

+

+

+

=+

33

22

11

vuvuvu

vu

)0,6,5()1,1,3()1,5,2()6,9()4,6()2,3(

=−+

=+

vu +

u

vgeometric algebraic

examples:

8

Vector-Vector Subtraction •  subtract: vector - vector = vector

!!!

"

#

$$$

%

&

=−

33

22

11

vuvuvu

vu

)2,4,1()1,1,3()1,5,2()2,3()4,6()2,3(

−=−−

−−=−

=− vu

uv

v−

)( vu −+

9

Vector-Vector Subtraction •  subtract: vector - vector = vector

!!!

"

#

$$$

%

&

=−

33

22

11

vuvuvu

vu

)2,4,1()1,1,3()1,5,2()2,3()4,6()2,3(

−=−−

−−=−

=− vu

uv

v−

)( vu −+

vu + v

u uv −v

uargument reversal

10

Scalar-Vector Multiplication •  multiply: scalar * vector = vector

•  vector is scaled

)*,*,*(* 321 uauauaa =u

)5,.5.2,1()1,5,2(*5.)4,6()2,3(*2

=

=

u*a

u

11

Vector-Vector Multiplication: Dot •  multiply v1: vector * vector = scalar •  dot product, aka inner product vu •

( ) ( ) ( )332211

3

2

1

3

2

1

vuvuvuvvv

uuu

∗+∗+∗=

"""

#

$

%%%

&

'

"""

#

$

%%%

&

'

12

Vector-Vector Multiplication: Dot •  multiply v1: vector * vector = scalar •  dot product, aka inner product vu •

( ) ( ) ( )332211

3

2

1

3

2

1

vuvuvuvvv

uuu

∗+∗+∗=

"""

#

$

%%%

&

'

"""

#

$

%%%

&

'

( ) ( ) ( )332211

3

2

1

3

2

1

vuvuvuvvv

uuu

∗+∗+∗=

"""

#

$

%%%

&

'

"""

#

$

%%%

&

'

13

Vector-Vector Multiplication: Dot •  multiply v1: vector * vector = scalar •  dot product, aka inner product

u1u2u3

"

#

$ $ $

%

&

' ' '

v1v2v3

"

#

$ $ $

%

&

' ' '

= u1 ∗v1( ) + u2 ∗v2( ) + u3 ∗v3( )

vu •

θcosvuvu =•

u

•  geometric interpretation •  lengths, angles •  can find angle between two vectors

14

Dot Product Geometry •  can find length of projection of u onto v

•  as lines become perpendicular,

θcosvuvu =• u

θcosu0→• vu

vvuu •

=θcos

15

Dot Product Example

19676)3*2()7*1()1*6(371

216

=++=++=

!!!

"

#

$$$

%

&

!!!

"

#

$$$

%

&

u1u2u3

"

#

$ $ $

%

&

' ' '

v1v2v3

"

#

$ $ $

%

&

' ' '

= u1 ∗v1( ) + u2 ∗v2( ) + u3 ∗v3( )

16

Vector-Vector Multiplication, Cross •  multiply v2: vector * vector = vector •  cross product

•  algebraic

!!!

"

#

$$$

%

&

=

!!!

"

#

$$$

%

&

×

!!!

"

#

$$$

%

&

1221

3113

2332

3

2

1

3

2

1

vuvuvuvuvuvu

vvv

uuu

Page 2: Vectors Column vs. Row Vectors Vector-Vector Addition ... · Math Basics Week 1, Fri Jan 8 2 Readings For Lecture ¥!Shirley/ Marschner (3rd edition) ... right hand rule: index finger

17

Vector-Vector Multiplication, Cross •  multiply v2: vector * vector = vector •  cross product

•  algebraic

!!!

"

#

$$$

%

&

=

!!!

"

#

$$$

%

&

×

!!!

"

#

$$$

%

&

1221

3113

2332

3

2

1

3

2

1

vuvuvuvuvuvu

vvv

uuu1

!!!

"

#

$$$

%

&

=

!!!

"

#

$$$

%

&

×

!!!

"

#

$$$

%

&

1221

3113

2332

3

2

1

3

2

1

vuvuvuvuvuvu

vvv

uuu

2 !!!

"

#

$$$

%

&

=

!!!

"

#

$$$

%

&

×

!!!

"

#

$$$

%

&

1221

3113

2332

3

2

1

3

2

1

vuvuvuvuvuvu

vvv

uuu

3

18

Vector-Vector Multiplication, Cross •  multiply v2: vector * vector = vector •  cross product

•  algebraic

•  geometric

•  parallelogram area

•  perpendicular to parallelogram

!!!

"

#

$$$

%

&

=

!!!

"

#

$$$

%

&

×

!!!

"

#

$$$

%

&

1221

3113

2332

3

2

1

3

2

1

vuvuvuvuvuvu

vvv

uuu

ba×

ba×

a×b = a b sinθ

a

bq

a × b

θ

19

RHS vs. LHS Coordinate Systems

•  right-handed coordinate system

•  left-handed coordinate system

xy

z

xyz

right hand rule: index finger x, second finger y; right thumb points up

left hand rule: index finger x, second finger y; left thumb points down

yxz ×=

yxz ×=

convention

20

Matrix-Matrix Addition

•  add: matrix + matrix = matrix

•  example

!"

#$%

&

++

++=!

"

#$%

&+!"

#$%

&

22222121

12121111

2221

1211

2221

1211

mnmnmnmn

nnnn

mmmm

!"

#$%

&−=!

"

#$%

&

++

+−+=!

"

#$%

&−+!"

#$%

&

5981

147253)2(1

1752

4231

21

Scalar-Matrix Multiplication

•  multiply: scalar * matrix = matrix

•  example

!"

#$%

&=!

"

#$%

&

2221

1211

2221

1211

****mamamama

mmmm

a

!"

#$%

&=!

"

#$%

&=!

"

#$%

&

153126

5*31*34*32*3

5142

3

22

Matrix-Matrix Multiplication

•  can only multiply (n,k) by (k,m): number of left cols = number of right rows •  legal

•  undefined !!!

"

#

$$$

%

&

!"

#$%

&

mlkjih

gfecba

!"

#$%

&

!!!

"

#

$$$

%

&

kjih

qg

pf

oe

cba

23

Matrix-Matrix Multiplication

•  row by column

!"

#$%

&=!

"

#$%

&!"

#$%

&

2221

1211

2221

1211

2221

1211

pppp

nnnn

mmmm

2112111111 nmnmp +=

24

Matrix-Matrix Multiplication

•  row by column

!"

#$%

&=!

"

#$%

&!"

#$%

&

2221

1211

2221

1211

2221

1211

pppp

nnnn

mmmm

2112111111 nmnmp +=

2122112121 nmnmp +=

25

Matrix-Matrix Multiplication

•  row by column

!"

#$%

&=!

"

#$%

&!"

#$%

&

2221

1211

2221

1211

2221

1211

pppp

nnnn

mmmm

2112111111 nmnmp +=

2212121112 nmnmp +=2122112121 nmnmp +=

26

Matrix-Matrix Multiplication

•  row by column

!"

#$%

&=!

"

#$%

&!"

#$%

&

2221

1211

2221

1211

2221

1211

pppp

nnnn

mmmm

2112111111 nmnmp +=

2212121112 nmnmp +=2122112121 nmnmp +=

2222122122 nmnmp +=

27

Matrix-Matrix Multiplication

•  row by column

•  noncommutative: AB != BA

!"

#$%

&=!

"

#$%

&!"

#$%

&

2221

1211

2221

1211

2221

1211

pppp

nnnn

mmmm

2112111111 nmnmp +=

2212121112 nmnmp +=2122112121 nmnmp +=

2222122122 nmnmp +=

28

Matrix-Vector Multiplication

•  points as column vectors: postmultiply

•  points as row vectors: premultiply

!!!!

"

#

$$$$

%

&

!!!!!

"

#

$$$$$

%

&

=

!!!!

"

#

$$$$

%

&

hzyx

mmmmmmmmmmmmmmmm

hzyx

44434241

34333231

24232221

14131211

''''

Mpp'=

[ ] [ ]

T

mmmmmmmmmmmmmmmm

hzyxhzyx

!!!!!

"

#

$$$$$

%

&

=

44434241

34333231

24232221

14131211

''''TTT Mpp' =

29

Matrices

•  transpose

•  identity

•  inverse •  not all matrices are invertible

!!!!!

"

#

$$$$$

%

&

=

!!!!!

"

#

$$$$$

%

&

44342414

43332313

42322212

41312111

44434241

34333231

24232221

14131211

mmmmmmmmmmmmmmmmT

mmmmmmmmmmmmmmmm

!!!!

"

#

$$$$

%

&

1000010000100001

IAA =−1

30

Matrices and Linear Systems

•  linear system of n equations, n unknowns

•  matrix form Ax=b

12513424273

=++

−=−−

=++

zyxzyxzyx

!!!

"

#

$$$

%

&

−=

!!!

"

#

$$$

%

&

!!!

"

#

$$$

%

&

−−

114

125342273

zyx

Basis Vectors and Frames

31 32

Basis Vectors

•  take any two vectors that are linearly independent (nonzero and nonparallel) •  can use linear combination of these to define

any other vector: bac 21 ww +=

2a

0.5bc = 2a + 0.5ba

c

b

Page 3: Vectors Column vs. Row Vectors Vector-Vector Addition ... · Math Basics Week 1, Fri Jan 8 2 Readings For Lecture ¥!Shirley/ Marschner (3rd edition) ... right hand rule: index finger

33

Orthonormal Basis Vectors

•  if basis vectors are orthonormal: orthogonal (mutually perpendicular) and unit length •  we have Cartesian coordinate system •  familiar Pythagorean definition of distance

2x0.5yc = 2x + 0.5y

x

y

0,1

=•

==

yx

yx

orthonormal algebraic properties

34

Basis Vectors and Origins

jiop yx ++=

o

p

i

j

•  coordinate system: just basis vectors •  can only specify offset: vectors

•  coordinate frame: basis vectors and origin •  can specify location as well as offset: points

35

Working with Frames

pF1

F1

ijo

jiop yx ++=

36

Working with Frames

pF1

F1 p = (3,-1)

ijo

jiop yx ++=

37

Working with Frames

pF1

F1 p = (3,-1)

ijo

jiop yx ++=

F1

38

Working with Frames

pF1

F1 p = (3,-1) F2

ijo

jiop yx ++=

F2

ijo

39

Working with Frames

pF1

F1 p = (3,-1) F2 p = (-1.5,2)

ijo

jiop yx ++=

F2

ijo

40

Working with Frames

pF1

F1 p = (3,-1) F2 p = (-1.5,2)

ij

F2

ijo

o

jiop yx ++=F2

41

Working with Frames

pF1

F1 p = (3,-1) F2 p = (-1.5,2)

F3

ij

F2

ijo

F3

ijo

o

jiop yx ++=

42

Working with Frames

pF1

F1 p = (3,-1) F2 p = (-1.5,2)

F3 p = (1,2)

ij

F2

ijo

F3

ijo

o

jiop yx ++=

43

Working with Frames

F1 p = (3,-1) F2 p = (-1.5,2)

F3 p = (1,2)

pF1

ij

F2

ijo

F3

ijo

o

jiop yx ++=

F3

44

Named Coordinate Frames

•  origin and basis vectors •  pick canonical frame of reference

•  then don’t have to store origin, basis vectors •  just •  convention: Cartesian orthonormal one on

previous slide •  handy to specify others as needed

•  airplane nose, looking over your shoulder, ... •  really common ones given names in CG

• object, world, camera, screen, ...

),,( cba=p

zyxop cba +++=