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

computer graphics cs 4731 lecture 12 linear algebra for
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Computer Graphics (CS 4731) Lecture 12: Linear Algebra for Graphics (Points, Scalars, Vectors) Prof Emmanuel Agu

Computer Science Dept. Worcester Polytechnic Institute (WPI)

slide-2
SLIDE 2

Points, Scalars and Vectors

 Points, vectors defined relative to a coordinate system

 Point: Location in coordinate system

 Example: Point (5,4)

y x

(5,4) (0,0) 5 4

slide-3
SLIDE 3

Vectors

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

Length

Angle

slide-4
SLIDE 4

Points

 Cannot add or scale points  Subtract 2 points = vector

Point

slide-5
SLIDE 5

Vector‐Point Relationship

 Diff. b/w 2 points = vector

v = Q – P

 point + vector = point

P + v = Q

P Q v

slide-6
SLIDE 6

Vector Operations

 Define vectors

) , (

3 2 , 1

a a a  a ) , (

3 2 , 1

b b b  b ) , (

3 3 2 2 , 1 1

b a b a b a      b a

Then vector addition:

a a+b b

slide-7
SLIDE 7

Vector Operations

 Define scalar, s  Scaling vector by a scalar

) , , (

3 2 1

s a s a s a s  a )) ( ), ( ), ( (

3 3 2 2 1 1

b a b a b a        b a

Note vector subtraction:

a b a-b a 2.5a

slide-8
SLIDE 8

Vector Operations: Examples

 Scaling vector by a scalar

 For example, if a=(2,5,6) and b=(‐2,7,1)

and s=6, then

) , , (

3 2 1

s a s a s a s  a

  • Vector addition:

) , (

3 3 2 2 , 1 1

b a b a b a      b a ) 7 , 12 , ( ) , (

3 3 2 2 , 1 1

      b a b a b a b a ) 36 , 30 , 12 ( ) , , (

3 2 1

  s a s a s a s a

slide-9
SLIDE 9

Affine Combination

 Given a vector  Affine combination: Sum of all components = 1  Convex affine = affine + no negative component

i.e

1 .........

2 1

  

n

a a a

negative non a a a

n

  ,......... ,

2 1

) ,..., , (

3 2 , 1 n

a a a a  a

slide-10
SLIDE 10

Magnitude of a Vector

 Magnitude of a  Normalizing a vector (unit vector)  Note magnitude of normalized vector = 1. i.e

2 2 2 2 1

.......... | |

n

a a a    a magnitude vector   a a a ˆ

1 ..........

2 2 2 2 1

  

n

a a a

slide-11
SLIDE 11

Magnitude of a Vector

 Example: if a = (2, 5, 6)  Magnitude of a  Normalizing a

65 6 5 2 | |

2 2 2

    a        65 6 , 65 5 , 65 2 ˆ a

slide-12
SLIDE 12

12

Convex Hull

 Smallest convex object containing P1P2,…..Pn  Formed by “shrink wrapping” points

slide-13
SLIDE 13

Dot Product (Scalar product)

 Dot product,  For example, if a=(2,3,1) and b=(0,4,‐1)

then

3 3 2 2 1 1

........ b a b a b a d         b a ) 1 1 ( ) 4 3 ( ) 2 (        b a 11 1 12    

slide-14
SLIDE 14

Properties of Dot Products

 Symmetry (or commutative):  Linearity:  Homogeneity:  And

a b b a    ) ( ) ( b a b a    s s b c b a b c a       ) ( b b b  

2

slide-15
SLIDE 15

Angle Between Two Vectors

c x b y

b

c

  

b b

  sin , cos b b b 

 

c c

  sin , cos c c c 

 cos c b c b  

Sign of b.c: b.c > 0

c b b

b.c = 0

b c c

b.c < 0

slide-16
SLIDE 16

Angle Between Two Vectors

 Find the angle b/w the vectors b = (3,4) and c =

(5,2)

slide-17
SLIDE 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  Step 2: Normalize vectors b and c

       5 4 , 5 3 ˆ b

       29 2 , 29 5 c ˆ

5 25 4 3 | |

2 2

    b 29 2 5 | |

2 2

   c

slide-18
SLIDE 18

Angle Between Two Vectors

 Step 3: Find angle as dot product  Step 4: Find angle as inverse cosine

               29 2 , 29 5 5 4 , 5 3 ˆ ˆ c b

326 . 31 ) 85422 . cos(   

c b ˆ ˆ 

85422 . 29 5 23 29 5 8 29 5 15 ˆ ˆ     c b

slide-19
SLIDE 19

Standard Unit Vectors

 

, , 1  i

Define

 

, 1 ,  j

 

1 , ,  k

So that any vector,

 

k j i v c b a c b a     , ,

y z x i j k

slide-20
SLIDE 20

Cross Product (Vector product)

 

z y x

a a a , ,  a

 

z y x

b b b , ,  b

If Then

k j i b a ) ( ) ( ) (

x y y x x z z x y z z y

b a b a b a b a b a b a       

Remember using determinant

z y x z y x

b b b a a a k j i

Note: a x b is perpendicular to a and b

slide-21
SLIDE 21

Cross Product

Note: a x b is perpendicular to both a and b a x b a b

slide-22
SLIDE 22

Cross Product

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

slide-23
SLIDE 23

Cross Product (Vector product)

 

8 , 1 , 4  b

Then

k j i b a ) 3 ( ) 8 24 ( ) 2 (       

Using determinant

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

 

2 , , 3  a

8 1 4 2 3 k j i

k j i 3 16 2    

slide-24
SLIDE 24

Normal for Triangle using Cross Product Method

p0 p1 p2 n plane n·(p - p0 ) = 0 n = (p2 - p0 ) ×(p1 - p0 ) normalize n  n/ |n| p Note that right‐hand rule determines outward face

slide-25
SLIDE 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

 Proposed by Martin Newell at Utah (teapot guy)

 Uses formulae, suitable for computer  Compute during mesh generation  Robust!

p0 p2 p1

slide-26
SLIDE 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)

PO P2 P1 (6,1,4) (7,0,9) (1,1,2) P1 - P0 P2 - P0

slide-27
SLIDE 27

Newell Method for Normal Vectors

 Formulae: Normal N = (mx, my, mz)

  

) ( 1 ) ( i next i N i i next i x

z z y y m   

 

  

) ( 1 ) ( i next i N i i next i y

x x z z m   

 

  

) ( 1 ) ( i next i N i i next i z

y y x x m   

 

slide-28
SLIDE 28

Newell Method for Normal Vectors

 Calculate x component of normal

  

) ( 1 ) ( i next i N i i next i x

z z y y m   

 

4 1 6 2 1 1 9 7 4 1 6 z y x

P0 P1 P2 P0

2 11 13 ) 6 )( ( ) 11 )( 1 ( ) 13 )( 1 (        

x x x

m m m

slide-29
SLIDE 29

Newell Method for Normal Vectors

 Calculate y component of normal

4 1 6 2 1 1 9 7 4 1 6 z y x

P0 P1 P2 P0

23 14 56 65 ) 7 )( 2 ( ) 8 )( 7 ( ) 13 )( 5 (           

y y y

m m m

  

) ( 1 ) ( i next i N i i next i y

x x z z m   

 

slide-30
SLIDE 30

Newell Method for Normal Vectors

 Calculate z component of normal

4 1 6 2 1 1 9 7 4 1 6 z y x

P0 P1 P2 P0

5 10 6 1 ) 2 )( 5 ( ) 1 )( 6 ( ) 1 )( 1 (           

z z z

m m m

  

) ( 1 ) ( i next i N i i next i z

y y x x m   

 

Note: Using Newell method yields same result as Cross product method (2,-23,-5)

slide-31
SLIDE 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

m e

  • m

r n a e

m a r m e r m a e 2       

Θ1 Θ2 Note: Θ1 = Θ2

slide-32
SLIDE 32

 Consider all points of the form

 P()=P0 +  d  Line: Set of all points that pass through P0 in direction

  • f vector d

Lines

slide-33
SLIDE 33

Parametric Form

 Two‐dimensional forms of a line

 Explicit: y = mx +h  Implicit: ax + by +c =0  Parametric:

x() = x0 + (1-)x1 y() = y0 + (1-)y1

 Parametric form of line

 More robust and general than other forms  Extends to curves and surfaces Po P1 α Pα 1 - α

slide-34
SLIDE 34

Convexity

 An object is convex iff for any two points in the

  • bject all points on the line segment between these

points are also in the object

P Q Q P convex not convex

slide-35
SLIDE 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(, )

slide-36
SLIDE 36

References

 Angel and Shreiner, Interactive Computer Graphics,

6th edition, Chapter 3

 Hill and Kelley, Computer Graphics using OpenGL, 3rd

edition, Sections 4.2 ‐ 4.4