Coputer Grphics (CS 543) Lecture 3 (Prt ): Liner Alger for Grphics (Points, Sclrs, Vectors) Prof Enuel Agu Coputer Science Dept. Worcester Poltechnic Institute (WPI)
Points, Sclrs nd Vectors Points, vectors defined reltive to coordinte sste Point: Loction in coordinte sste Eple: 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 diensions Length Angle
Vector-Point Reltionship Sutrct points = vector v = Q P P point + vector = point P + v = Q v Q
Vector Opertions Define vectors (,, 3), ) (, 3 Then vector ddition: (,, 3 3 ) +
Vector Opertions Define sclr, s Scling vector sclr s ( s, s, 3 s ) Note vector sutrction: ( ( ), ( ), 3 ( 3 )) -.5
Vector Opertions: Eples Scling vector sclr s ( s, s, 3 s ) Vector ddition: (,, 3 3 ) For eple, if =(,5,6) nd =(-,7,) nd s=6, then ( 3,, 3 ) (0,,7) s ( 3 s, s, s) (,30,36)
Affine Cointion Given vector (,, 3,..., n... n Affine cointion: Su of ll coponents = ) Conve ffine = ffine + no negtive coponent i.e,,... n non negtive
Mgnitude of Vector Mgnitude of... n Norliing vector (unit vector) â vector gnitude Note gnitude of norlied vector =. i.e... n
Mgnitude of Vector Eple: if = (, 5, 6) Mgnitude of 5 6 65 Norliing â 65, 5 65, 6 65
Conve Hull Sllest conve oject contining P,P,..P n Fored shrink wrpping points
Dot Product (Sclr product) Dot product, d... 3 3 For eple, if =(,3,) nd =(0,4,-) then ( 0) (3 4) ( ) 0
Properties of Dot Products Setr (or couttive): Linerit: Hoogeneit: And ) ( ) ( s s c c ) (
Angle Between Two Vectors c c c cos, sin c cos, c sin c c c c cos Sign of.c: c c c.c > 0.c = 0.c < 0
Angle Between Two Vectors Prole: Find ngle /w vectors = (3,4) nd c = (5,) Step : Find gnitudes of vectors nd c Step : Norlie 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 5 9 5 8 9 5 3 9 0.854 Step 4: Find ngle s inverse cosine cos( 0.854) 3.36
Stndrd Unit Vectors Define i j,0,0 0,,0 k i k 0,0, 0 j So tht n vector, v, c i j ck,
Cross Product (Vector product),,,, If Then k j i ) ( ) ( ) ( Reeer using deterinnt 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,,8) 3,0, 4,,8 Using deterinnt i j k 3 0 4 8 Then ( 0 ) i (4 8) j (3 0) k i 6j 3k
Norl for Tringle using Cross Product Method plne n (p - p 0 ) = 0 n p n = (p - p 0 ) (p - p 0 ) norlie n n/ n p p 0 p Note tht right-hnd rule deterines outwrd fce
Newell Method for Norl Vectors Proles with cross product ethod: clcultion difficult hnd, tedious If vectors lost prllel, cross product is sll Nuericl inccurc result p Proposed Mrtin Newell t Uth (tepot gu) Uses forule, suitle for coputer Copute during esh genertion Roust! p 0 p
Newell Method Eple Eple: Find norl of polgon with vertices P0 = (6,,4), P=(7,0,9) nd P = (,,) Using siple cross product: ((7,0,9)-(6,,4)) X ((,,)-(6,,4)) = (,-3,-5) P - P0 P - P0 P (,,) PO (6,,4) P (7,0,9)
Newell Method for Norl Vectors Forule: Norl N = (,, ) N i0 N i0 N i0 i net( i) i net( i) i net( i) i net( i) i net( i) i net( i)
Newell Method for Norl Vectors Clculte coponent of norl N i0 i net( i) i net( i) P0 6 4 ()(3) ( )() (0)(6) 3 0 P P P0 7 6 0 9 4
Newell Method for Norl Vectors Clculte coponent of norl N i0 i net( i) i net( i) P0 6 4 ( 5)(3) (7)(8) ( )(7) 65 56 4 3 P P P0 7 6 0 9 4
Newell Method for Norl Vectors Clculte coponent of norl N i0 i net( i) i net( i) ( )() (6)() ( 5)() 6 0 5 P0 P P P0 6 7 6 0 4 9 4 Note: Using Newell ethod ields se result s Cross product ethod (,-3,-5)
Finding Vector Reflected Fro Surfce = originl vector n = norl vector r = reflected vector = projection of long n e = projection of orthogonl to n Note: Θ = Θ n e r r e Θ Θ - r e e
Fors of Eqution of Line Two-diensionl fors of line Eplicit: = +h Iplicit: + +c =0 Pretric: () = 0 + (-) () = 0 + (-) Pretric for of line - α More roust nd generl thn other fors Etends to curves nd surfces P o α P α P
Conveit An oject is conve iff for n two points in the oject ll points on the line segent etween these points re lso in the oject P P Q Q conve not conve
References Angel nd Shreiner, Interctive Coputer Grphics, 6 th edition, Chpter 3 Hill nd Kelle, Coputer Grphics using OpenGL, 3 rd edition, Sections 4. - 4.4