computer graphics cs 4731 lecture 12 linear algebra for
play

Computer Graphics (CS 4731) Lecture 12: Linear Algebra for Graphics - PowerPoint PPT Presentation

Computer Graphics (CS 4731) Lecture 12: Linear Algebra for Graphics (Points, Scalars, Vectors) Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI) Points, Scalars and Vectors Points, vectors defined relative to a


  1. Computer Graphics (CS 4731) Lecture 12: Linear Algebra for Graphics (Points, Scalars, Vectors) Prof Emmanuel Agu Computer Science Dept. Worcester Polytechnic Institute (WPI)

  2. Points, Scalars and Vectors  Points, vectors defined relative to a coordinate system  Point: Location in coordinate system  Example: Point (5,4) y 5 (5,4) 4 (0,0) x

  3. Vectors  Magnitude  Direction  NO position  Can be added, scaled, rotated Length  CG vectors: 2, 3 or 4 dimensions Angle

  4. Points  Cannot add or scale points  Subtract 2 points = vector Point

  5. Vector ‐ Point Relationship  Diff. b/w 2 points = vector v = Q – P P v  point + vector = point Q P + v = Q

  6. Vector Operations  Define vectors Then vector addition:  ( , ) a a a a 1 , 2 3  b     ( , ) a  a b a b a b ( , ) b b b b 1 1 , 2 2 3 3 1 , 2 3 a a+b b

  7. Vector Operations  Define scalar, s Note vector subtraction:  Scaling vector by a scalar  b s  ( , , ) a a a s a s a s 1 2 3        ( ( ), ( ), ( )) a b a b a b 1 1 2 2 3 3 a a-b a 2.5a b

  8. Vector Operations: Examples  Scaling vector by a scalar • Vector addition: s   b     ( , , ) ( , ) a a a s a s a s a b a b a b 1 2 3 1 1 , 2 2 3 3  For example, if a =(2,5,6) and b = ( ‐ 2,7,1) and s =6, then       ( , ) ( 0 , 12 , 7 ) a b a b a b a b 1 1 , 2 2 3 3   ( , , ) ( 12 , 30 , 36 ) a s a s a s a s 1 2 3

  9. Affine Combination  Given a vector  ( , ,..., ) a a a a a 1 , 2 3 n    ......... 1 a a a 1 2 n  Affine combination: Sum of all components = 1  Convex affine = affine + no negative component i.e   , ,......... a a a non negative 1 2 n

  10. Magnitude of a Vector  Magnitude of a 2 2 2    | | .......... a a a a 1 2 n  Normalizing a vector (unit vector) a vector  a  ˆ a magnitude  Note magnitude of normalized vector = 1. i.e 2 2 2    .......... 1 a a a 1 2 n

  11. Magnitude of a Vector  Example: if a = (2, 5, 6)     2 2 2 | | 2 5 6 65  Magnitude of a a  Normalizing a   2 5 6  ˆ   , , a  65 65 65 

  12. Convex Hull  Smallest convex object containing P 1  P 2 ,…..P n  Formed by “shrink wrapping” points 12

  13. Dot Product (Scalar product)  Dot product,         ........ a b d a b a b a b 1 1 2 2 3 3  For example, if a =(2,3,1) and b= (0,4, ‐ 1) then  b        ( 2 0 ) ( 3 4 ) ( 1 1 ) a     0 12 1 11

  14. Properties of Dot Products  Symmetry (or commutative):    a b b a  Linearity:  )      ( a c b a b c b  Homogeneity:    ( ) ( ) a b a b s s   2  And b b b

  15. Angle Between Two Vectors y   b    cos , sin b b c b b   c    cos , sin c c  c c b     cos b c b c c  b x b b b Sign of b.c : c c c b.c > 0 b.c < 0 b.c = 0

  16. Angle Between Two Vectors  Find the angle b/w the vectors b = (3,4) and c = (5,2)

  17. Angle Between Two Vectors  Find the angle b/w vectors b = (3,4) and c = (5,2)  Step 1: Find magnitudes of vectors b and c     2 2 | | 3 4 25 5 b    2 2 | | 5 2 29 c  Step 2: Normalize vectors b and c     3 4 5 2 ˆ   ˆ     , c , b 5 5    29 29 

  18. Angle Between Two Vectors ˆ  b ˆ c  Step 3: Find angle as dot product     3 4 5 2 ˆ      ˆ  ,  , b c  5 5   29 29  15 8 23 ˆ  c     ˆ 0 . 85422 b 5 29 5 29 5 29  Step 4: Find angle as inverse cosine    cos( 0 . 85422 ) 31 . 326 

  19. Standard Unit Vectors y Define    1 , 0 , 0 i i k    0 , 1 , 0 j   j 0  0 , 0 , 1 k z x So that any vector,       , , v i j k a b c a b c

  20. Cross Product (Vector product) If       , , , , a a a a b b b b x y z x y z Then        ( ) ( ) ( ) a b i j k a b a b a b a b a b a b y z z y x z z x x y y x Remember using determinant i j k a a a x y z b b b x y z Note: a x b is perpendicular to a and b

  21. Cross Product Note: a x b is perpendicular to both a and b a x b 0 a b

  22. Cross Product Calculate a x b if a = (3,0,2) and b = (4,1,8)

  23. Cross Product (Vector product) Calculate a x b if a = (3,0,2) and b = (4,1,8)      4 , 1 , 8  b 3 , 0 , 2 a Using determinant i j k 3 0 2 4 1 8 Then        ( 0 2 ) ( 24 8 ) ( 3 0 ) a b i j k     2 16 3 i j k

  24. Normal for Triangle using Cross Product Method n p 2 n · ( p - p 0 ) = 0 plane n = ( p 2 - p 0 ) × ( p 1 - p 0 ) p p 1 normalize n  n/ |n| p 0 Note that right ‐ hand rule determines outward face

  25. Newell Method for Normal Vectors  Problems with cross product method:  calculation difficult by hand, tedious  If 2 vectors almost parallel, cross product is small  Numerical inaccuracy may result p 1 p 2 p 0  Proposed by Martin Newell at Utah (teapot guy )  Uses formulae, suitable for computer  Compute during mesh generation  Robust!

  26. Newell Method Example  Example: Find normal of polygon with vertices P0 = (6,1,4), P1=(7,0,9) and P2 = (1,1,2)  Using simple cross product: ((7,0,9) ‐ (6,1,4)) X ((1,1,2) ‐ (6,1,4)) = (2, ‐ 23, ‐ 5) P1 - P0 P2 P2 - P0 (1,1,2) PO (6,1,4) P1 (7,0,9)

  27. Newell Method for Normal Vectors  Formulae: Normal N = (mx, my, mz)     1 N     m y y z z ( ) ( ) x i next i i next i  0 i     1 N     m z z x x ( ) ( ) y i next i i next i  0 i     1 N     m x x y y ( ) ( ) z i next i i next i  0 i

  28. Newell Method for Normal Vectors  Calculate x component of normal     1 x y z N     m y y z z ( ) ( ) x i next i i next i 6 1 4  0 P0 i 7 0 9 P1     ( 1 )( 13 ) ( 1 )( 11 ) ( 0 )( 6 ) m 1 1 2 x P2    13 11 0 m x 6 1 4  P0 2 m x

  29. Newell Method for Normal Vectors  Calculate y component of normal x y z     1 N     m z z x x ( ) ( ) 6 1 4 y i next i i next i P0  0 i 7 0 9 P1      ( 5 )( 13 ) ( 7 )( 8 ) ( 2 )( 7 ) m 1 1 2 y P2     65 56 14 m y 6 1 4 P0   23 m y

  30. Newell Method for Normal Vectors  Calculate z component of normal x y z     1 N     m x x y y 6 1 4 ( ) ( ) P0 z i next i i next i  0 i 7 0 9 P1      ( 1 )( 1 ) ( 6 )( 1 ) ( 5 )( 2 ) m 1 1 2 z P2     1 6 10 m z 6 1 4   P0 5 m z Note: Using Newell method yields same result as Cross product method (2,-23,-5)

  31. Finding Vector Reflected From a Surface a = original vector  n = normal vector  r = reflected vector  m = projection of a along n  e = projection of a orthogonal to n  n Note: Θ 1 = Θ 2 a r   e a m m -m   Θ 1 r e m Θ 2    2 r a m e e

  32. Lines  Consider all points of the form  P(  )=P 0 +  d  Line: Set of all points that pass through P 0 in direction of vector d

  33. Parametric Form  Two ‐ dimensional forms of a line  Explicit: y = mx +h  Implicit: ax + by +c =0 α P 1  Parametric: x(  ) =  x 0 + (1-  )x 1 1 - α P α y(  ) =  y 0 + (1-  )y 1 P o  Parametric form of line  More robust and general than other forms  Extends to curves and surfaces

  34. Convexity  An object is convex iff for any two points in the object all points on the line segment between these points are also in the object P P Q Q not convex convex

  35. Curves and Surfaces  Curves: 1 ‐ parameter non ‐ linear functions of the form P(  )  Surfaces: two ‐ parameter functions P(  ,  )  Linear functions give planes and polygons P(  ) P(  ,  )

  36. References  Angel and Shreiner, Interactive Computer Graphics, 6 th edition, Chapter 3  Hill and Kelley, Computer Graphics using OpenGL, 3 rd edition, Sections 4.2 ‐ 4.4

Recommend


More recommend