Computer Grphics (CS 4731) Lecture 7: Liner Alger for Grphics (Points, Sclrs, Vectors) Prof Emmnuel Agu Computer Science Dept. Worcester Poltechnic Institute (WPI)
Annoncements Project 1 due net Tuesd, 11.59PM. Midterm in clss net Frid SAs will give the em. I will e w Smple midterm (A 14) lred on clss wesite All code from ook (working progrms) on ook wesite. Quite useful. Tke look
Points, Sclrs nd Vectors Points, vectors defined reltive to coordinte sstem Point: Loction in coordinte sstem Emple: Point (5,4) Cnnot dd or scle points 5 (5,4) 4 (0,0)
Vectors Mgnitude Direction NO position Cn e dded, scled, rotted CG vectors:, 3 or 4 dimensions Length Angle
Vector-Point Reltionship Sutrct points = vector v = Q P P point + vector = point P + v = Q v Q
Vector Opertions Define vectors ( 1,, 3), ) ( 1, 3 Then vector ddition: ( 1 1,, 3 3 ) +
Vector Opertions Define sclr, s Scling vector sclr s ( s, s, 3 1 s ) Note vector sutrction: ( 1 ( 1 ), ( ), 3 ( 3 )) -.5
Vector Opertions: Emples Scling vector sclr Vector ddition: s ( s, s, 3 1 s ) ( 1 1,, 3 3 ) For emple, if =(,5,6) nd =(-,7,1) nd s=6, then ( 3 1 1,, 3 ) (0,1,7) s ( 3 1s, s, s) (1,30,36)
Affine Comintion Given vector (,, 3,..., 1 n 1... n 1 Affine comintion: Sum of ll components = 1 ) Conve ffine = ffine + no negtive component i.e 1,,... n non negtive
Mgnitude of Vector Mgnitude of 1... n Normliing vector (unit vector) â vector mgnitude Note mgnitude of normlied vector = 1. i.e 1... n 1
Mgnitude of Vector Emple: if = (, 5, 6) Mgnitude of 5 6 65 Normliing â 65, 5 65, 6 65
Conve Hull Smllest conve oject contining P 1,P,..P n Formed shrink wrpping points 1
Dot Product (Sclr product) Dot product, d 1 1... 3 3 For emple, if =(,3,1) nd =(0,4,-1) then ( 0) (3 4) (1 1) 01 111
Properties of Dot Products Smmetr (or commuttive): Linerit: Homogeneit: And ) ( ) ( s s c c ) (
Angle Between Two Vectors c cos, sin c c cos, c sin c c c c c cos Sign of.c: c c c.c > 0.c = 0.c < 0
Angle Between Two Vectors Prolem: Find ngle /w vectors = (3,4) nd c = (5,) Step 1: Find mgnitudes of vectors nd c Step : Normlie vectors nd c 5 4, 5 3 ˆ 9, 9 5 ĉ 5 5 4 3 9 5 c
Angle Between Two Vectors Step 3: Find ngle s dot product ˆ cˆ ˆ cˆ 3 5, 4 5 5 9, 9 ˆ cˆ 5 15 9 5 8 9 5 3 9 0.854 Step 4: Find ngle s inverse cosine cos( 0.854) 31.36
Stndrd Unit Vectors Define i j 1,0,0 0,1,0 k i k 0,0,1 0 j So tht n vector, v, c i j ck,
Cross Product (Vector product),,,, If Then k j i ) ( ) ( ) ( Rememer using determinnt k j i Note: is perpendiculr to nd
Cross Product Note: is perpendiculr to oth nd 0
Cross Product (Vector product) Clculte if = (3,0,) nd = (4,1,8) 3,0, 4,1,8 Using determinnt i j k 3 0 4 1 8 Then ( 0 ) i (4 8) j (3 0) k i 16j 3k
Norml for Tringle using Cross Product Method plne n (p - p 0 ) = 0 n p n = (p - p 0 ) (p 1 - p 0 ) normlie n n/ n p p 0 p 1 Note tht right-hnd rule determines outwrd fce
Newell Method for Norml Vectors Prolems with cross product method: clcultion difficult hnd, tedious If vectors lmost prllel, cross product is smll Numericl inccurc m result p 1 Proposed Mrtin Newell t Uth (tepot gu) Uses formule, suitle for computer Compute during mesh genertion Roust! p 0 p
Newell Method Emple Emple: Find norml of polgon with vertices P0 = (6,1,4), P1=(7,0,9) nd P = (1,1,) Using simple cross product: ((7,0,9)-(6,1,4)) X ((1,1,)-(6,1,4)) = (,-3,-5) P1 - P0 P - P0 P (1,1,) PO (6,1,4) P1 (7,0,9)
Newell Method for Norml Vectors Formule: Norml N = (m, m, m) m m m N 1 i0 N 1 i0 N 1 i0 i net( i) i net( i) i net( i) i net( i) i net( i) i net( i)
Newell Method for Norml Vectors Clculte component of norml m N 1 i0 i net( i) i net( i) P0 6 1 4 m m m (1)(13) ( 1)(11) (0)(6) 1311 0 P1 P P0 7 1 6 0 1 1 9 4
Newell Method for Norml Vectors Clculte component of norml m N 1 i0 i net( i) i net( i) P0 6 1 4 m m m ( 5)(13) (7)(8) ( )(7) 65 56 14 3 P1 P P0 7 1 6 0 1 1 9 4
Newell Method for Norml Vectors Clculte component of norml m m m m N 1 i0 i net( i) i net( i) ( 1)(1) (6)(1) ( 5)() 1 6 10 5 P0 P1 P P0 6 7 1 6 1 0 1 1 4 9 4 Note: Using Newell method ields sme result s Cross product method (,-3,-5)
Finding Vector Reflected From Surfce = originl vector n = norml vector r = reflected vector m = projection of long n e = projection of orthogonl to n n Note: Θ 1 = Θ e m r r e m m Θ 1 Θ -m r m e e
Forms of Eqution of Line Two-dimensionl forms of line Eplicit: = m +h Implicit: + +c =0 Prmetric: () = 0 + (1-) 1 () = 0 + (1-) 1 Prmetric form of line 1 - α More roust nd generl thn other forms Etends to curves nd surfces P o α P α P 1
Conveit An oject is conve iff for n two points in the oject ll points on the line segment etween these points re lso in the oject P P Q Q conve not conve
References Angel nd Shreiner, Interctive Computer Grphics, 6 th edition, Chpter 3 Hill nd Kelle, Computer Grphics using OpenGL, 3 rd edition, Sections 4. - 4.4