math basics week 1, fri jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 named...

44
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

Upload: others

Post on 09-Sep-2019

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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

Page 2: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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

Page 3: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

Vectors and Matrices

3

Page 4: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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

Page 5: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

5

Vectors

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

•  offset / displacement •  location if given origin

Page 6: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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

Page 7: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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:

Page 8: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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 −+

Page 9: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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

Page 10: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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

Page 11: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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

∗+∗+∗=

"""

#

$

%%%

&

'

"""

#

$

%%%

&

'

Page 12: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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

∗+∗+∗=

"""

#

$

%%%

&

'

"""

#

$

%%%

&

'

Page 13: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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

Page 14: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

14

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

•  as lines become perpendicular,

θcosvuvu =• u

θcosu0→• vu

vvuu •

=θcos

Page 15: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

15

Dot Product Example

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

216

=++=++=

!!!

"

#

$$$

%

&

!!!

"

#

$$$

%

&

u1u2u3

"

#

$ $ $

%

&

' ' '

v1v2v3

"

#

$ $ $

%

&

' ' '

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

Page 16: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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 17: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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

Page 18: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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

θ

Page 19: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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

Page 20: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

20

Matrix-Matrix Addition

•  add: matrix + matrix = matrix

•  example

!"

#$%

&

++

++=!

"

#$%

&+!"

#$%

&

22222121

12121111

2221

1211

2221

1211

mnmnmnmn

nnnn

mmmm

!"

#$%

&−=!

"

#$%

&

++

+−+=!

"

#$%

&−+!"

#$%

&

5981

147253)2(1

1752

4231

Page 21: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

21

Scalar-Matrix Multiplication

•  multiply: scalar * matrix = matrix

•  example

!"

#$%

&=!

"

#$%

&

2221

1211

2221

1211

****mamamama

mmmm

a

!"

#$%

&=!

"

#$%

&=!

"

#$%

&

153126

5*31*34*32*3

5142

3

Page 22: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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

Page 23: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

23

Matrix-Matrix Multiplication

•  row by column

!"

#$%

&=!

"

#$%

&!"

#$%

&

2221

1211

2221

1211

2221

1211

pppp

nnnn

mmmm

2112111111 nmnmp +=

Page 24: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

24

Matrix-Matrix Multiplication

•  row by column

!"

#$%

&=!

"

#$%

&!"

#$%

&

2221

1211

2221

1211

2221

1211

pppp

nnnn

mmmm

2112111111 nmnmp +=

2122112121 nmnmp +=

Page 25: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

25

Matrix-Matrix Multiplication

•  row by column

!"

#$%

&=!

"

#$%

&!"

#$%

&

2221

1211

2221

1211

2221

1211

pppp

nnnn

mmmm

2112111111 nmnmp +=

2212121112 nmnmp +=2122112121 nmnmp +=

Page 26: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

26

Matrix-Matrix Multiplication

•  row by column

!"

#$%

&=!

"

#$%

&!"

#$%

&

2221

1211

2221

1211

2221

1211

pppp

nnnn

mmmm

2112111111 nmnmp +=

2212121112 nmnmp +=2122112121 nmnmp +=

2222122122 nmnmp +=

Page 27: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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 +=

Page 28: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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' =

Page 29: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

29

Matrices

•  transpose

•  identity

•  inverse •  not all matrices are invertible

!!!!!

"

#

$$$$$

%

&

=

!!!!!

"

#

$$$$$

%

&

44342414

43332313

42322212

41312111

44434241

34333231

24232221

14131211

mmmmmmmmmmmmmmmmT

mmmmmmmmmmmmmmmm

!!!!

"

#

$$$$

%

&

1000010000100001

IAA =−1

Page 30: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

30

Matrices and Linear Systems

•  linear system of n equations, n unknowns

•  matrix form Ax=b

12513424273

=++

−=−−

=++

zyxzyxzyx

!!!

"

#

$$$

%

&

−=

!!!

"

#

$$$

%

&

!!!

"

#

$$$

%

&

−−

114

125342273

zyx

Page 31: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

Basis Vectors and Frames

31

Page 32: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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 33: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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

Page 34: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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

Page 35: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

35

Working with Frames

pF1

F1

ijo

jiop yx ++=

Page 36: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

36

Working with Frames

pF1

F1 p = (3,-1)

ijo

jiop yx ++=

Page 37: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

37

Working with Frames

pF1

F1 p = (3,-1)

ijo

jiop yx ++=

F1

Page 38: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

38

Working with Frames

pF1

F1 p = (3,-1) F2

ijo

jiop yx ++=

F2

ijo

Page 39: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

39

Working with Frames

pF1

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

ijo

jiop yx ++=

F2

ijo

Page 40: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

40

Working with Frames

pF1

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

ij

F2

ijo

o

jiop yx ++=F2

Page 41: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

41

Working with Frames

pF1

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

F3

ij

F2

ijo

F3

ijo

o

jiop yx ++=

Page 42: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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 ++=

Page 43: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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

Page 44: Math Basics Week 1, Fri Jan 8 - cs.ubc.catmm/courses/314-16/slides/mathbasics.pdf · 44 Named Coordinate Frames • origin and basis vectors • pick canonical frame of reference

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 +++=