You are on page 1of 7

Course: Next Steps

Foundations of Computer Graphics §  Complete HW 0


§  Sets up basic compilation issues
Online Lecture 2: Review of Basic Math §  Verifies you can work with feedback/grading servers

Vectors and Dot Products §  First few lectures core math ideas in graphics
§  This lecture is a revision of basic math concepts

§  HW 1 has few lines of code (but start early)


Ravi Ramamoorthi §  Use some ideas discussed in lecture, create images

§  Textbooks: None required


§  OpenGL/GLSL reference helpful (but not required)

Motivation and Outline Vectors


§  Many graphics concepts need basic math like linear algebra
§  Vectors (dot products, cross products, …) =
§  Matrices (matrix-matrix, matrix-vector mult., …)
§  E.g: a point is a vector, and an operation like translating  
Usually written as a or in bold. Magnitude written as a
or rotating points on object can be matrix-vector multiply §  Length and direction. Absolute position not important
§  Should be refresher on very basic material for most of you
§  Only basic high school math required
§  Use to store offsets, displacements, locations
§  But strictly speaking, positions are not vectors and cannot be added:
a location implicitly involves an origin, while an offset does not.

Vector Addition Cartesian Coordinates


a A=4X+3Y
= b+
a+b b

a
X

( )
⎛ x ⎞
A = ⎜ ⎟
T
A = x y A = x2 + y 2
§  Geometrically: Parallelogram rule ⎝ y ⎠
§  In cartesian coordinates (next), simply add coords §  X and Y can be any (usually orthogonal unit) vectors

1
Vector Multiplication Dot (scalar) product
b
§  Dot product
§  Cross product φ
§  Orthonormal bases and coordinate frames a

aib = bia = ?
§  Note: We use right-handed (standard) coordinates

Dot (scalar) product Dot (scalar) product


b b

φ φ
a a

aib = bia = ? a i b = a b cosφ aib = bia = ? a i b = a b cosφ


⎛ aib ⎞ a i (b + c) = a i b + a i c ⎛ aib ⎞
φ = cos−1 ⎜ ⎟ (ka) i b = a i (kb) = k(a i b) φ = cos−1 ⎜ ⎟
⎝ a b⎠ ⎝ a b⎠

Dot product in Cartesian components Dot product in Cartesian components


⎛ x ⎞ ⎛ x ⎞ ⎛ x ⎞ ⎛ x ⎞
a
ab = ⎜ ⎟ ⎜ b ⎟ = ? ab = ⎜
a
⎟ ⎜ b ⎟ = ?
⎜⎝ y a ⎟⎠ ⎜⎝ y b ⎟⎠ ⎜⎝ y a ⎟⎠ ⎜⎝ y b ⎟⎠

⎛ x ⎞ ⎛ x ⎞
a
ab = ⎜ ⎟  ⎜ b ⎟ = xa xb + y a y b
⎜⎝ y a ⎟⎠ ⎜⎝ y b ⎟⎠

2
Dot product: some applications in CG Projections (of b on a)
b
§  Find angle between two vectors (e.g. cosine of angle
between light source and surface for shading)
φ
a
§  Finding projection of one vector on another (e.g.
aib
coordinates of point in arbitrary coordinate system) b → a = b cosφ =
b→a =? a
§  Advantage: computed easily in cartesian components b→a =? a aib
b→a= b→a = 2
a
a a

Vector Multiplication
Foundations of Computer Graphics §  Dot product
Online Lecture 2: Review of Basic Math §  Cross product
Vectors: Cross Products §  Orthonormal bases and coordinate frames

Ravi Ramamoorthi §  Note: We use right-handed (standard) coordinates

Cross (vector) product Cross product: Properties


a × b = −b × a
a × b = a b sinφ x × y = +z
a × b = −b × a
b y × x = −z
φ a×a = 0
y × z = +x
a × (b + c) = a × b + a × c
a z × y = −x
§  Cross product orthogonal to two initial vectors a × (kb) = k(a × b)
z × x = +y
§  Direction determined by right-hand rule x × z = −y
§  Useful in constructing coordinate systems (later)

3
Cross product: Cartesian formula? Cross product: Cartesian formula?
x y z ⎛ y z −y z ⎞
⎜ a b b a

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
⎜ ⎟⎜ ⎟
a × b = A*b = ⎜ za 0 −xa ⎟ ⎜ y b ⎟
⎜ ⎟⎜ ⎟
⎜⎝ −y a xa 0 ⎟⎠ ⎜⎝ zb⎟⎠
Dual matrix of vector a

Vector Multiplication
Foundations of Computer Graphics §  Dot product
Online Lecture 2: Review of Basic Math §  Cross product
Vectors: Orthonormal Basis Frames §  Orthonormal bases and coordinate frames
Ravi Ramamoorthi
§  Note: We use right-handed (standard) coordinates

Orthonormal bases/coordinate frames Coordinate Frames


§  Important for representing points, positions, locations §  Any set of 3 vectors (in 3D) so that
u = v = w =1
§  Often, many sets of coordinate systems (not just X, Y, Z)
§  Global, local, world, model, parts of model (head, hands, …) u iv = v iw = u iw = 0
w = u ×v
§  Critical issue is transforming between these systems/bases
§  Topic of next 3 lectures p = (p i u)u + (p i v)v + (p i w)w

4
Constructing a coordinate frame Constructing a coordinate frame?
§  Often, given a vector a (viewing direction in HW1), want to We want to associate w with a, and v with b
construct an orthonormal basis §  But a and b are neither orthogonal nor unit norm
§  And we also need to find u
§  Need a second vector b (up direction of camera in HW1)
§  Construct an orthonormal basis (for instance, camera
coordinate frame to transform world objects into in HW1)

Constructing a coordinate frame? Constructing a coordinate frame?


We want to associate w with a, and v with b We want to associate w with a, and v with b
§  But a and b are neither orthogonal nor unit norm §  But a and b are neither orthogonal nor unit norm
§  And we also need to find u §  And we also need to find u
a a
w= w=
a a
b×w
u=
b×w

Constructing a coordinate frame?


We want to associate w with a, and v with b Foundations of Computer Graphics
§  But a and b are neither orthogonal nor unit norm
§  And we also need to find u Online Lecture 2: Review of Basic Math
a Matrices
w=
a
b×w
u= Ravi Ramamoorthi
b×w
v =w ×u

5
Matrices What is a matrix
§  Can be used to transform points (vectors) §  Array of numbers (m×n = m rows, n columns)
§  Translation, rotation, shear, scale
(more detail next lecture) ⎛ 1 3 ⎞
⎜ ⎟
⎜ 5 2 ⎟
⎝ 0 4 ⎠
§  Addition, multiplication by a scalar simple:
element by element

Matrix-matrix multiplication Matrix-matrix multiplication


§  Number of columns in first must = rows in second §  Number of columns in first must = rows in second

⎛ 1 3 ⎞ ⎛ 1 3 ⎞ ⎛ 9 27 33 13 ⎞
⎜ ⎟⎛ 3 6 9 4 ⎞ ⎜ ⎟⎛ 3 6 9 4 ⎞ ⎜ ⎟
⎜ 5 2 ⎟ ⎜⎝ 2 7 8 3 ⎟⎠ ⎜ 5 2 ⎟ ⎜⎝ 2 7 8 3 ⎟⎠ = ⎜ 19 44 61 26 ⎟
⎝ 0 4 ⎠ ⎝ 0 4 ⎠ ⎝ 8 28 32 12 ⎠

§  Element (i,j) in product is dot product of row i of first §  Element (i,j) in product is dot product of row i of first
matrix and column j of second matrix matrix and column j of second matrix

Matrix-matrix multiplication Matrix-matrix multiplication


§  Number of columns in first must = rows in second §  Number of columns in first must = rows in second
⎛ 1 3 ⎞ ⎛ 9 27 33 13 ⎞ ⎛ 1 3 ⎞ ⎛ 9 27 33 13 ⎞
⎜ ⎟⎛ 3 6 9 4 ⎞ ⎜ ⎟ ⎜ ⎟⎛ 3 6 9 4 ⎞ ⎜ ⎟
⎜ 5 2 =
⎟ ⎜⎝ 2 7 8 3 ⎟⎠ ⎜ 19 44 61 26 ⎟ ⎜ 5 2 =
⎟ ⎜⎝ 2 7 8 3 ⎟⎠ ⎜ 19 44 61 26 ⎟
⎝ 0 4 ⎠ ⎝ 8 28 32 12 ⎠ ⎝ 0 4 ⎠ ⎝ 8 28 32 12 ⎠

§  Element (i,j) in product is dot product of row i of first §  Element (i,j) in product is dot product of row i of first
matrix and column j of second matrix matrix and column j of second matrix

6
Matrix-matrix multiplication Matrix-Vector Multiplication
§  Number of columns in first must = rows in second §  Key for transforming points (next lecture)
⎛ 1 3 ⎞
⎛ 3 6 9 4 ⎞⎜ ⎟ §  Treat vector as a column matrix (m×1)
⎜ ⎟ 5 2 NOT EVEN LEGAL!!
⎝ 2 7 8 3 ⎠ ⎜⎝ 0 4 ⎟⎠
§  Non-commutative (AB and BA are different in general) §  E.g. 2D reflection about y-axis
§  Associative and distributive ⎛ −1 0 ⎞ ⎛ x ⎞ ⎛ −x ⎞
§  A(B+C) = AB + AC ⎜ ⎟⎜ ⎟ =⎜ ⎟
§  (A+B)C = AC + BC ⎝ 0 1 ⎠⎝ y ⎠ ⎝ y ⎠

Transpose of a Matrix (or vector?) Identity Matrix and Inverses

⎛ 1 0 0 ⎞
T
⎛ 1 2 ⎞
⎜ ⎟ ⎛ 1 3 5 ⎞
⎜ 3 4 ⎟ = ⎜⎝ 2 4 6 ⎟⎠ ⎜ ⎟
⎝ 5 6 ⎠
I3×3 =⎜ 0 1 0 ⎟
⎝ 0 0 1 ⎠
(AB)T = BT AT
AA−1 = A−1A = I
(AB)−1 = B −1A−1

Vector multiplication in Matrix form


a  b = aT b
§  Dot product?
⎛ x ⎞

(x )
⎜ b ⎟
a
ya za (
⎜ y b ⎟ = xa xb + y a y b + za zb )
⎜ ⎟
⎜⎝ zb ⎟⎠
⎛ 0 −za y a ⎞ ⎛ xb ⎞
*
⎜ ⎟⎜ ⎟
§  Cross product? a × b = A b = ⎜ za 0 −xa ⎟ ⎜ y b ⎟
⎜ ⎟⎜ ⎟
⎜⎝ −y a xa 0 ⎟⎠ ⎜⎝ zb ⎟⎠
Dual matrix of vector a

You might also like