Foundtions of Computer Grphics (Spring 2010) CS 184, Lecture 2: Review of Bsic Mth http://inst.eecs.erkeley.edu/~cs184 o Do Complete Assignment 0 Downlod nd compile skeleton for ssignment 1 Red instructions re setting up your system Ask A if ny prolems, need visul C++ etc. We won t nswer compiltion issues fter next lecture ry to otin textooks, set up progrmming environment. Let us know if ny prolems. Aout first few lectures Somewht technicl: core mth ides in grphics HW1 is simple (only few lines of code): Lets you see how to use some ides discussed in lecture, crete imges Motivtion nd Outline Mny grphics concepts need sic mth like liner lger Vectors (dot products, cross products, ) Mtrices (mtrix-mtrix, mtrix-vector mult., ) E.g: point is vector, nd n opertion like trnslting or rotting points on oject cn e mtrix-vector multiply Chpters 2.4 (vectors) nd 5.2.1,5.2.2 (mtrices) Worthwhile to red ll of chpters 2 nd 5 Should e refresher on very sic mteril for most of you If not understnd, tlk to me (review in office hours) Vectors Length nd direction. Asolute position not importnt Usully written s or in old. Mgnitude written s = Use to store offsets, displcements, loctions But strictly speking, positions re not vectors nd cnnot e dded: loction implicitly involves n origin, while n offset does not. Vector Addition Crtesin Coordintes + = + A = 4 X +3Y Geometriclly: Prllelogrm rule In crtesin coordintes (next), simply dd coords X X nd Y cn e ny (usully orthogonl unit) vectors x y 2 2 A A x y A x y 1
Vector Multipliction Dot product (2.4.3) Cross product (2.4.4) Orthonorml ses nd coordinte frmes (2.4.5,6) Dot (sclr) product Note: ook tlks out right nd left-hnded coordinte systems. We lwys use right-hnded? ( c) c ( k) ( k) k( ) cos 1 cos Dot product: some pplictions in CG Find ngle etween two vectors (e.g. cosine of ngle etween light source nd surfce for shding) Projections (of on ) Finding projection of one vector on nother (e.g. coordintes of point in ritrry coordinte system) Advntge: computed esily in crtesin components?? cos 2 Dot product in Crtesin components x x? y y x x xx yy y y Vector Multipliction Dot product (2.4.3) Cross product (2.4.4) Orthonorml ses nd coordinte frmes (2.4.5,6) Note: ook tlks out right nd left-hnded coordinte systems. We lwys use right-hnded 2
Cross (vector) product sin Cross product orthogonl to two initil vectors Direction determined y right-hnd rule Useful in constructing coordinte systems (lter) Cross product: Properties x y z y xz y z x z y x z xy x z y 0 ( c) c ( k) k( ) Cross product: Crtesin formul? x y z yz yz x y z zx xz x y z xy yx 0 z y x y x 0 z Dul mtrix of vector * A z 0 x y Vector Multipliction Dot product (2.4.3) Cross product (2.4.4) Orthonorml ses nd coordinte frmes (2.4.5,6) Note: ook tlks out right nd left-hnded coordinte systems. We lwys use right-hnded Orthonorml ses/coordinte frmes Importnt for representing points, positions, loctions Often, mny sets of coordinte systems (not just X, Y, Z) Glol, locl, world, model, prts of model (hed, hnds, ) Criticl issue is trnsforming etween these systems/ses opic of next 3 lectures Coordinte Frmes Any set of 3 vectors (in 3D) so tht u v w 1 uv vw uw 0 wuv p ( puu ) ( pvv ) ( pww ) 3
Constructing coordinte frme Often, given vector (viewing direction in HW1), wnt to construct n orthonorml sis Need second vector (up direction of cmer in HW1) Construct n orthonorml sis (for instnce, cmer coordinte frme to trnsform world ojects into in HW1) Constructing coordinte frme? We wnt to ssocite w with, nd v with But nd re neither orthogonl nor unit norm And we lso need to find u w u w w v wu Mtrices Cn e used to trnsform points (vectors) rnsltion, rottion, sher, scle (more detil next lecture) Section 5.2.1 nd 5.2.2 of text Instructive to red ll of 5 ut not tht relevnt to course Wht is mtrix Arry of numers (m n = m rows, n columns) 1 3 0 4 Addition, multipliction y sclr simple: element y element Mtrix-mtrix multipliction Numer of columns in first must = rows in second 1 3 3 6 9 4 0 4 Mtrix-mtrix multipliction Numer of columns in first must = rows in second 1 3 9 27 33 13 3 6 9 4 19 44 61 26 0 4 8 28 32 12 mtrix nd column j of second mtrix mtrix nd column j of second mtrix 4
Mtrix-mtrix multipliction Numer of columns in first must = rows in second 1 3 9 27 33 13 3 6 9 4 19 44 61 26 0 4 8 28 32 12 Mtrix-mtrix multipliction Numer of columns in first must = rows in second 1 3 9 27 33 13 3 6 9 4 19 44 61 26 0 4 8 28 32 12 mtrix nd column j of second mtrix mtrix nd column j of second mtrix Mtrix-mtrix multipliction Numer of columns in first must = rows in second 1 3 3 6 9 4 NO EVEN LEGAL!! 0 4 Non-commuttive (AB nd BA re different in generl) Associtive nd distriutive A(B+C) = AB + AC (A+B)C = AC + BC Mtrix-Vector Multipliction Key for trnsforming points (next lecture) ret vector s column mtrix (m 1) E.g. 2D reflection out y-xis (from textook) 1 0x x 0 1y y rnspose of Mtrix (or vector?) 1 2 1 3 5 3 4 2 4 6 5 6 ( AB) B A Identity Mtrix nd Inverses 1 0 0 I33 0 1 0 0 0 1 1 1 AA A A I 1 1 1 ( AB) B A 5
Vector multipliction in Mtrix form Dot product? Cross product? x z x y z y x x y y z z 0 z y x y x 0 z Dul mtrix of vector * A z 0 x y 6