Math Review - Fabio Pellacinipellacini.di.uniroma1.it/.../lectures/02_mathreview.pdf ·...

16
© 2017 Fabio Pellacini and Steve Marschner • Computer Graphics Math Review 1

Transcript of Math Review - Fabio Pellacinipellacini.di.uniroma1.it/.../lectures/02_mathreview.pdf ·...

Page 1: Math Review - Fabio Pellacinipellacini.di.uniroma1.it/.../lectures/02_mathreview.pdf · 2017-12-06 · • Linear algebra operations: sum and scalar product • Dot product: scalar

© 2017 Fabio Pellacini and Steve Marschner • Computer Graphics

Math Review

1

Page 2: Math Review - Fabio Pellacinipellacini.di.uniroma1.it/.../lectures/02_mathreview.pdf · 2017-12-06 · • Linear algebra operations: sum and scalar product • Dot product: scalar

• Point: location in space

• Vector: orientation with an associated magnitude

– difference between points

– Direction: orientation with unit magnitude

– In cartesian coordinates, representation with 3 numbers

© 2017 Fabio Pellacini and Steve Marschner • Computer Graphics

Geometric Quantities

2

p = (px, py, pz) v = (vx, vy, vz) d = (dx, dy, dz)

Page 3: Math Review - Fabio Pellacinipellacini.di.uniroma1.it/.../lectures/02_mathreview.pdf · 2017-12-06 · • Linear algebra operations: sum and scalar product • Dot product: scalar

• Most graphics software uses linear algebra vectors for all points, directions and (geometric) vectors

• Indicated with 3 cartesian coordinates

• Typical Implementation using simple structs

© 2017 Fabio Pellacini and Steve Marschner • Computer Graphics

Linear Algebra Vectors

3

v =

2

4vxvyvz

3

5

struct vec3f { float x, y, z;

}

Page 4: Math Review - Fabio Pellacinipellacini.di.uniroma1.it/.../lectures/02_mathreview.pdf · 2017-12-06 · • Linear algebra operations: sum and scalar product • Dot product: scalar

• Linear algebra operations: sum and scalar product

• Dot product: scalar equal to the product of the vectors’ lengths times the cosine between them

– used to check whether two vectors are orthogonal

• Vector length: square root of the dot product

© 2017 Fabio Pellacini and Steve Marschner • Computer Graphics

Vector Arithmetic

4

u+ v =

2

4ux + vxux + vyuz + vz

3

5 sv =

2

4svxsvysvz

3

5

u · v = uxvx + uyvy + uzvz = |u||v| cos ✓

l =q

v2x + v2y + v2z =pv · v

Page 5: Math Review - Fabio Pellacinipellacini.di.uniroma1.it/.../lectures/02_mathreview.pdf · 2017-12-06 · • Linear algebra operations: sum and scalar product • Dot product: scalar

• Cross product: vector orthogonal to the operands, whose length is equal to the product of the vectors’ lengths times the sine between them

• Used to construct orthonormal vectors

© 2017 Fabio Pellacini and Steve Marschner • Computer Graphics

Vector Arithmetic

5

|u⇥ v| = |u||v| sin ✓(u⇥ v) · u = 0

(u⇥ v) · v = 0

u⇥ v =

2

4uyvz � uzvyuzvx � uxvzuxvy � uyvx

3

5

Page 6: Math Review - Fabio Pellacinipellacini.di.uniroma1.it/.../lectures/02_mathreview.pdf · 2017-12-06 · • Linear algebra operations: sum and scalar product • Dot product: scalar

• Points, vectors, directions are defined w.r.t. a coordinate system

• Coordinate systems, or frames, specify an origin and three axis

– if not defined, we intend the “unit” or “world” frame

© 2017 Fabio Pellacini and Steve Marschner • Computer Graphics

Coordinate Systems

6

F =�x,y, z,o

struct frame3f { vec3f x, y, z, o;

}

Page 7: Math Review - Fabio Pellacinipellacini.di.uniroma1.it/.../lectures/02_mathreview.pdf · 2017-12-06 · • Linear algebra operations: sum and scalar product • Dot product: scalar

• Given a frame defined w.r.t world space, we can transform a point coordinates to/from the coordinate frame

• World to local: subtract origin, project onto the frame axes

• Local to world: add origin to the scaled frame axes

© 2017 Fabio Pellacini and Steve Marschner • Computer Graphics

Coordinate Systems

7

pl =

2

4(p� o) · x(p� o) · y(p� o) · z

3

5 p = o+ plxx+ plyy + plzz

Page 8: Math Review - Fabio Pellacinipellacini.di.uniroma1.it/.../lectures/02_mathreview.pdf · 2017-12-06 · • Linear algebra operations: sum and scalar product • Dot product: scalar

• Vector transforms as difference of points

• Boils down to ignoring the origin

© 2017 Fabio Pellacini and Steve Marschner • Computer Graphics

Coordinate Systems

8

vl =

2

4v · xv · yv · z

3

5 v = vlxx+ vlyy + vlzz

Page 9: Math Review - Fabio Pellacinipellacini.di.uniroma1.it/.../lectures/02_mathreview.pdf · 2017-12-06 · • Linear algebra operations: sum and scalar product • Dot product: scalar

• Consider only 3x3 matrices for now

• Write in column notation

© 2017 Fabio Pellacini and Steve Marschner • Computer Graphics

Matrices

9

M =

2

4M11 M12 M13

M21 M22 M23

M31 M32 M33

3

5

M =⇥x y z

⇤=

2

4xx yx zxxy yy zyxz yz zz

3

5

Page 10: Math Review - Fabio Pellacinipellacini.di.uniroma1.it/.../lectures/02_mathreview.pdf · 2017-12-06 · • Linear algebra operations: sum and scalar product • Dot product: scalar

• Matrix-vector multiply: weighted sum of matrix’ columns

• Matrix-matrix multiply: columns are matrix-vector multiplies

• Matrix inverse

– analytic for small matrices, numerical for all others

© 2017 Fabio Pellacini and Steve Marschner • Computer Graphics

Matrices

10

Mv = vxx+ vyy + vzz

MM 0 =⇥Mx0,My0,Mz0

MM�1 = M�1M = I

Page 11: Math Review - Fabio Pellacinipellacini.di.uniroma1.it/.../lectures/02_mathreview.pdf · 2017-12-06 · • Linear algebra operations: sum and scalar product • Dot product: scalar

• Transpose: flip the row and columns

• Orthonormal matrices: columns are orthogonal to each other and normalized

• Orthonormal inverse is its transpose

© 2017 Fabio Pellacini and Steve Marschner • Computer Graphics

Matrices

11

M =⇥mij

⇤! MT =

⇥Mji

Mo =⇥ci⇤, ci · cj =

(0 for i = j

1 for i = j

M�1o = MT

o

Page 12: Math Review - Fabio Pellacinipellacini.di.uniroma1.it/.../lectures/02_mathreview.pdf · 2017-12-06 · • Linear algebra operations: sum and scalar product • Dot product: scalar

• Define a matrix whose columns are the coordinate frame axes

• Matrix is orthonormal

• Express coordinate transformations with algebra operations

© 2017 Fabio Pellacini and Steve Marschner • Computer Graphics

Matrices and Frames

12

F =�x,y, z,o

M =

⇥x y z

p = Mpl + o v = Mvl

pl = MT (p� o) vl = MTv

Page 13: Math Review - Fabio Pellacinipellacini.di.uniroma1.it/.../lectures/02_mathreview.pdf · 2017-12-06 · • Linear algebra operations: sum and scalar product • Dot product: scalar

• Make a vector orthogonal to another by subtracting its projection

• Create a frame from z’ and y’

– normalize z’

– make y’ orthogonal to z and normalize it

– compute x as cross product of z and y

© 2017 Fabio Pellacini and Steve Marschner • Computer Graphics

Constructing Frames

13

u? = u� (u · v)v

z =z0

|z0| y =y0 � (y0 · z)z|y0 � (y0 · z)z| x = z⇥ y

Page 14: Math Review - Fabio Pellacinipellacini.di.uniroma1.it/.../lectures/02_mathreview.pdf · 2017-12-06 · • Linear algebra operations: sum and scalar product • Dot product: scalar

• Equation to tell whether we are on the curve or surface

• Example: line (orthogonal to u, distance k from 0)

• Example: circle (center p, radius r)

• Always define boundary of region

– (if f is continuous)

© 2017 Fabio Pellacini and Steve Marschner • Computer Graphics

Implicit curves

14

(u is a unit vector)

{v | (v � p) · (v � p)� r2 = 0}

Page 15: Math Review - Fabio Pellacinipellacini.di.uniroma1.it/.../lectures/02_mathreview.pdf · 2017-12-06 · • Linear algebra operations: sum and scalar product • Dot product: scalar

• Also called parametric

• Equation to map domain into plane

• Example: line (containing p, parallel to u)

• Example: circle (center b, radius r)

• Like tracing out the path of a particle over time

• Variable t is the “parameter”

© 2017 Fabio Pellacini and Steve Marschner • Computer Graphics

Explicit curves

15

Page 16: Math Review - Fabio Pellacinipellacini.di.uniroma1.it/.../lectures/02_mathreview.pdf · 2017-12-06 · • Linear algebra operations: sum and scalar product • Dot product: scalar

• In the previous slides we often changed between algebraic notation to geometric concepts

• This is very common in graphics

• In general, we tend to use algebraic concepts as much as possible since they are simpler to handle and easier to implement

© 2017 Fabio Pellacini and Steve Marschner • Computer Graphics

Algebra-vs-geometry views

16