Course: Next Steps: Foundations of Computer Graphics
Course: Next Steps: Foundations of Computer Graphics
Online Lecture 2: Review of Basic Math Vectors and Dot Products Ravi Ramamoorthi
Complete HW 0
Sets up basic compilation issues Verifies you can work with feedback/grading servers This lecture is a revision of basic math concepts
First few lectures core math ideas in graphics HW 1 has few lines of code (but start early) Textbooks: None required
Use some ideas discussed in lecture, create images OpenGL/GLSL reference helpful (but not required)
Vectors
=
Usually written as a or in bold. Magnitude written as a Length and direction. Absolute position not important
But strictly speaking, positions are not vectors and cannot be added: a location implicitly involves an origin, while an offset does not.
Vector Addition
a = +b
a
Geometrically: Parallelogram rule In cartesian coordinates (next), simply add coords
Cartesian Coordinates
A=4X+3Y
b+
a
b
x A = y
A =
x y
A = x2 + y 2
Vector Multiplication
Dot product Cross product Orthonormal bases and coordinate frames
aib = bia = ?
Note: We use right-handed (standard) coordinates
aib = bia = ?
x x a b =? a b= ya yb
x x a b =? a b= ya yb
x x a b = xa xb + y a y b a b= ya yb
Projections (of b on a)
b
Finding projection of one vector on another (e.g. coordinates of point in arbitrary coordinate system) Advantage: computed easily in cartesian components
ba =? ba =?
b a = b cos = ba= ba
aib a
a aib = a 2 a a
Vector Multiplication
Dot product Cross product Orthonormal bases and coordinate frames Note: We use right-handed (standard) coordinates
y z y z b a a b a b = xa y a za = za xb xa zb xb y b zb xa y b y a xb 0 z y a xb a 0 xa y b a b = A*b = za 0 zb y a xa x y z
Vector Multiplication
Dot product Cross product Orthonormal bases and coordinate frames Note: We use right-handed (standard) coordinates
Coordinate Frames
Any set of 3 vectors (in 3D) so that
w=
a a
w= u=
a a
bw bw
a w= a u=
bw bw
v =w u
Matrices
Can be used to transform points (vectors)
Translation, rotation, shear, scale (more detail next lecture)
What is a matrix
Array of numbers (mn = m rows, n columns)
1 3 5 2 0 4
Addition, multiplication by a scalar simple: element by element
Matrix-matrix multiplication
Number of columns in first must = rows in second
1 3 3 6 9 4 5 2 2 7 8 3 0 4
Matrix-matrix multiplication
Number of columns in first must = rows in second
9 27 33 13 1 3 3 6 9 4 5 2 2 7 8 3 = 19 44 61 26 8 28 32 12 0 4
Element (i,j) in product is dot product of row i of first matrix and column j of second matrix
Element (i,j) in product is dot product of row i of first matrix and column j of second matrix
Matrix-matrix multiplication
Number of columns in first must = rows in second
9 27 33 13 1 3 3 6 9 4 = 19 44 61 26 5 2 2 7 8 3 8 28 32 12 0 4
Matrix-matrix multiplication
Number of columns in first must = rows in second
9 27 33 13 1 3 3 6 9 4 = 19 44 61 26 5 2 2 7 8 3 8 28 32 12 0 4
Element (i,j) in product is dot product of row i of first matrix and column j of second matrix
Element (i,j) in product is dot product of row i of first matrix and column j of second matrix
Matrix-matrix multiplication
Number of columns in first must = rows in second
1 3 3 6 9 4 5 2 NOT EVEN LEGAL!! 2 7 8 3 0 4 Non-commutative (AB and BA are different in general)
Associative and distributive A(B+C) = AB + AC (A+B)C = AC + BC
Matrix-Vector Multiplication
Key for transforming points (next lecture) Treat vector as a column matrix (m1) E.g. 2D reflection about y-axis
1 0 x x = 0 1 y y
(AB)T = BT AT
(x
Cross product?
ya
za
0 a b = A b = za y a
*
x b y b = xa xb + y a y b + za zb zb
za 0 xa
y a xb xa y b 0 zb