computer graphics cs 543 lecture 4 part 2 linear algebra
play

Computer Graphics (CS 543) Lecture 4(Part 2): Linear Algebra for - PowerPoint PPT Presentation

Computer Graphics (CS 543) Lecture 4(Part 2): 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 543) Lecture 4(Part 2): 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  Example: Point (5,4) y (5,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 Location in coordinate system  Cannot add or scale  Subtract 2 points = vector  Point

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

  6. Vector Operations  Define vectors Then vector addition:  ( , ) a a a a 1 , 2 3   b     ( , ) ( , ) b a a b a b a b b b b 1 , 2 3 1 1 , 2 2 3 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 the vectors b = (3,4) and c = (5,2)  | b |= 5, | c |= 5.385 ˆ  3 4   c    ˆ 0 . 85422 cos ˆ b   ,  b  5 5    31 . 326 

  18. 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

  19. 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

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

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

  22. Cross Product Calculate a x b if a = (3,0,2) and b = (4,1,8) a x b = -2 i – 16 j + 3 k

  23. 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

  24. 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!

  25. 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)

  26. 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 Using Newell method, for previous example plug in values result is same: Normal is (2, -23, -5)

  27. 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

  28. 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

  29. 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

  30. 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

  31. 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(  ,  )

  32. 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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend