x a t x 2 y 2 a a x y y 1 vector multiplication dot
play

( ) x A T = x 2 + y 2 A = A = x y y 1 Vector - PDF document

To Do Foundations of Computer Graphics Complete Assignment 0 (a due 29, b due 31) (Fall 2012) Get help if issues with compiling, programming CS 184, Lecture 2: Review of Basic Math Textbooks: access to OpenGL references


  1. To Do Foundations of Computer Graphics § Complete Assignment 0 (a due 29, b due 31) (Fall 2012) § Get help if issues with compiling, programming CS 184, Lecture 2: Review of Basic Math § Textbooks: access to OpenGL references http://inst.eecs.berkeley.edu/~cs184 § About first few lectures § Somewhat technical: core math ideas in graphics § HW1 is simple (only few lines of code): Lets you see how to use some ideas discussed in lecture, create images 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 or Usually written as  a or in bold. Magnitude written as  rotating points on object can be matrix-vector multiply a § Length and direction. Absolute position not important § Should be refresher on very basic material for most of you § Use to store offsets, displacements, locations § Only basic high school math required § But strictly speaking, positions are not vectors and cannot be added: § If you don ’ t understand, talk to me (review in office hours) a location implicitly involves an origin, while an offset does not. Vector Addition Cartesian Coordinates A = 4 X + 3 Y a+b = b+a b a X § Geometrically: Parallelogram rule § X and Y can be any (usually orthogonal unit ) vectors § In cartesian coordinates (next), simply add coords ⎛ ⎞ ( ) x A T = x 2 + y 2 A = A = x y ⎜ ⎟ y ⎝ ⎠ 1

  2. Vector Multiplication Dot (scalar) product b § Dot product § Cross product φ § Orthonormal bases and coordinate frames a a i b = a b cos φ a i b = b i a = ? § Note: Some books talk about right and left-handed coordinate systems. We always use right-handed ⎛ ⎞ a i ( b + c ) = a i b + a i c a i b φ = cos − 1 ⎜ ⎟ ( ka ) i b = a i ( kb ) = k ( a i b ) a b ⎝ ⎠ Dot product in Cartesian components Dot product: some applications in CG ⎛ ⎞ ⎛ ⎞ § Find angle between two vectors (e.g. cosine of angle x a x b between light source and surface for shading) a � b = ⎜ ⎟ � ⎜ ⎟ = ? ⎜ ⎟ ⎜ ⎟ y a y b ⎝ ⎠ ⎝ ⎠ § Finding projection of one vector on another (e.g. coordinates of point in arbitrary coordinate system) ⎛ ⎞ ⎛ ⎞ x a x b a � b = ⎜ ⎟ � ⎜ ⎟ = x a x b + y a y b ⎜ ⎟ ⎜ ⎟ y a y b § Advantage: computed easily in cartesian components ⎝ ⎠ ⎝ ⎠ Projections (of b on a) Vector Multiplication b § Dot product § Cross product φ § Orthonormal bases and coordinate frames a b → a = b cos φ = a i b b → a = ? a § Note: Some books talk about right and left-handed b → a = ? b → a = b → a a = a i b coordinate systems. We always use right-handed 2 a a a 2

  3. Cross (vector) product Cross product: Properties a × b = − b × a x × y = + z a × b = a b sin φ a × b = − b × a y × x = − z b a × a = 0 y × z = + x φ a × ( b + c ) = a × b + a × c z × y = − x a × ( kb ) = k ( a × b ) z × x = + y a x × z = − y § Cross product orthogonal to two initial vectors § Direction determined by right-hand rule § Useful in constructing coordinate systems (later) Vector Multiplication Cross product: Cartesian formula? § Dot product ⎛ ⎞ y a z b − y b z a x y z ⎜ ⎟ § Cross product a × b = = z a x b − x a z b x a y a z a ⎜ ⎟ ⎜ ⎟ § Orthonormal bases and coordinate frames ⎜ x a y b − y a x b ⎟ x b y b z b ⎝ ⎠ ⎛ ⎞ ⎛ ⎞ − z a 0 y a x b ⎜ ⎟ ⎜ ⎟ a × b = A * b = − x a ⎜ z a 0 ⎟ ⎜ y b ⎟ § Note: book talks about right and left-handed ⎜ ⎟ ⎜ ⎟ coordinate systems. We always use right-handed ⎜ − y a ⎟ ⎜ ⎟ x a 0 z b ⎝ ⎠ ⎝ ⎠ Dual matrix of vector a Coordinate Frames Orthonormal bases/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 i v = v i w = u i w = 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 3

  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) w = a § Construct an orthonormal basis (for instance, camera a coordinate frame to transform world objects into in HW1) u = b × w b × w v = w × u 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 5 2 ⎜ 19 44 61 26 ⎜ ⎟ ⎜ ⎟ ⎜ ⎟ ⎜ ⎟ ⎝ ⎠ ⎝ 2 7 8 3 ⎠ 2 7 8 3 ⎝ ⎠ 0 4 ⎝ ⎠ ⎝ ⎠ 0 4 8 28 32 12 § 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 4

  5. 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 19 44 61 26 5 2 19 44 61 26 ⎜ ⎜ ⎜ ⎟ ⎜ ⎟ ⎜ ⎟ ⎜ ⎟ ⎝ ⎠ ⎝ ⎠ 2 7 8 3 2 7 8 3 ⎝ ⎠ ⎝ ⎠ ⎝ ⎠ ⎝ ⎠ 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 Matrix-matrix multiplication Matrix-Vector Multiplication § Number of columns in first must = rows in second § Key for transforming points (next lecture) § Treat vector as a column matrix (m × 1) ⎛ ⎞ 1 3 ⎛ ⎞ ⎜ ⎟ 3 6 9 4 5 2 ⎟ NOT EVEN LEGAL!! ⎜ ⎟ ⎜ ⎝ 2 7 8 3 ⎠ ⎝ 0 4 ⎠ § E.g. 2D reflection about y-axis § Non-commutative (AB and BA are different in general) ⎛ ⎞ ⎛ ⎞ ⎛ ⎞ − x − 1 0 x ⎟ = ⎜ ⎜ ⎟ ⎜ ⎟ § Associative and distributive ⎝ ⎠ y y 0 1 ⎝ ⎠ ⎝ ⎠ § A(B+C) = AB + AC § (A+B)C = AC + BC Transpose of a Matrix (or vector?) Identity Matrix and Inverses ⎛ ⎞ T ⎛ ⎞ 1 0 0 1 2 ⎛ ⎞ ⎜ ⎟ 1 3 5 ⎜ ⎟ = 3 4 ⎜ ⎟ ⎜ ⎟ I 3 × 3 = 0 1 0 ⎝ 2 4 6 ⎠ ⎜ ⎟ ⎝ 5 6 ⎠ ⎝ ⎠ 0 0 1 ( AB ) T = B T A T AA − 1 = A − 1 A = I ( AB ) − 1 = B − 1 A − 1 5

  6. Vector multiplication in Matrix form § Dot product? a � b = a T b ⎛ ⎞ x b ( ) ⎜ ⎟ ( ) ⎜ ⎟ = x a x b + y a y b + z a z b x a y a z a y b ⎜ ⎟ ⎜ ⎟ z b ⎝ ⎠ § Cross product? ⎛ ⎞ ⎛ ⎞ − z a 0 y a x b ⎜ ⎟ ⎜ ⎟ a × b = A * b = − x a ⎜ z a 0 ⎟ ⎜ y b ⎟ ⎜ ⎟ ⎜ ⎟ ⎜ − y a ⎟ ⎜ ⎟ x a 0 z b ⎝ ⎠ ⎝ ⎠ Dual matrix of vector a 6

Recommend


More recommend