![Page 1: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/1.jpg)
Computer Graphics (CS 543)Lecture 3c: Linear Algebra for Graphics
(Points, Scalars, Vectors)
Prof Emmanuel Agu
Computer Science Dept.
Worcester Polytechnic Institute (WPI)
![Page 2: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/2.jpg)
Points, Scalars and Vectors
Points, vectors defined relative to a coordinate system
Point: Location in coordinate system
Example: Point (5,4)
Cannot add or scale points
y
x
(5,4)
(0,0)
5
4
![Page 3: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/3.jpg)
Vectors
Magnitude
Direction
NO position
Can be added, scaled, rotated
CG vectors: 2, 3 or 4 dimensionsLength
Angle
![Page 4: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/4.jpg)
Vector-Point Relationship
Subtract 2 points = vector
v = Q – P
point + vector = point
P + v = Q
P
Q
v
![Page 5: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/5.jpg)
Vector Operations
Define vectors),( 32,1 aaaa
),( 32,1 bbbb ),( 3322,11 bababa ba
Then vector addition:
aa+b
b
![Page 6: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/6.jpg)
Vector Operations
Define scalar, s
Scaling vector by a scalar),,( 321 sasasas a
))(),(),(( 332211 bababa
ba
Note vector subtraction:
a
b
a-ba
2.5a
![Page 7: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/7.jpg)
Vector Operations: Examples
Scaling vector by a scalar
For example, if a=(2,5,6) and b=(-2,7,1) and s=6, then
),,( 321 sasasas a
•Vector addition:
),( 3322,11 bababa ba
)7,12,0(),( 3322,11 babababa
)36,30,12(),,( 321 sasasasa
![Page 8: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/8.jpg)
Affine Combination
Given a vector
Affine combination: Sum of all components = 1
Convex affine = affine + no negative componenti.e
1.........21 naaa
negativenonaaa n ,........., 21
),...,,( 32,1 naaaaa
![Page 9: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/9.jpg)
Magnitude of a Vector
Magnitude of a
Normalizing a vector (unit vector)
Note magnitude of normalized vector = 1. i.e
22
2
2
1 ..........|| naaa a
magnitude
vector
a
aa
1..........22
2
2
1 naaa
![Page 10: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/10.jpg)
Magnitude of a Vector
Example: if a = (2, 5, 6)
Magnitude of a
Normalizing a
65652|| 222 a
65
6,
65
5,
65
2a
![Page 11: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/11.jpg)
11
Convex Hull
Smallest convex object containing P1,P2,…..Pn
Formed by “shrink wrapping” points
![Page 12: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/12.jpg)
Dot Product (Scalar product)
Dot product,
For example, if a=(2,3,1) and b=(0,4,-1)
then
332211 ........ bababad ba
)11()43()02( ba
111120
![Page 13: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/13.jpg)
Properties of Dot Products
Symmetry (or commutative):
Linearity:
Homogeneity:
And
abba
)()( baba ss
bcbabca )(
bbb 2
![Page 14: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/14.jpg)
Angle Between Two Vectors
c
x
b
y
bc
bb sin,cos bbb
cc sin,cos ccc
coscbcb
Sign of b.c:
b.c > 0
c
b
b
b.c = 0
b
cc
b.c < 0
![Page 15: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/15.jpg)
Angle Between Two Vectors
Problem: Find 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
3b
29
2,
29
5c
52543|| 22 b
2925|| 22 c
![Page 16: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/16.jpg)
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ˆˆ cb
326.31)85422.0cos(
cb ˆˆ
85422.0295
23
295
8
295
15ˆˆ cb
![Page 17: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/17.jpg)
Standard Unit Vectors
0,0,1i
Define
0,1,0j
1,0,0k
So that any vector,
kjiv cbacba ,,
y
z x
i
j
k
0
![Page 18: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/18.jpg)
Cross Product (Vector product)
zyx aaa ,,a
zyx bbb ,,b
If
Then
kjiba )()()( xyyxxzzxyzzy babababababa
Remember using determinant
zyx
zyx
bbb
aaa
kji
Note: a x b is perpendicular to a and b
![Page 19: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/19.jpg)
Cross Product
Note: a x b is perpendicular to both a and b
a x b
a0
b
![Page 20: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/20.jpg)
Cross Product (Vector product)
8,1,4b
Then
kjiba )03()824()20(
Using determinant
Calculate a x b if a = (3,0,2) and b = (4,1,8)
2,0,3a
814
203
kji
kji 3162
![Page 21: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/21.jpg)
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
![Page 22: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/22.jpg)
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
![Page 23: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/23.jpg)
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
![Page 24: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/24.jpg)
Newell Method for Normal Vectors
Formulae: Normal N = (mx, my, mz)
)(
1
0
)( inexti
N
i
inextix zzyym
)(
1
0
)( inexti
N
i
inextiy xxzzm
)(
1
0
)( inexti
N
i
inextiz yyxxm
![Page 25: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/25.jpg)
Newell Method for Normal Vectors
Calculate x component of normal
)(
1
0
)( inexti
N
i
inextix zzyym
416
211
907
416
zyx
P0
P1
P2
P02
01113
)6)(0()11)(1()13)(1(
x
x
x
m
m
m
![Page 26: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/26.jpg)
Newell Method for Normal Vectors
Calculate y component of normal
416
211
907
416
zyx
P0
P1
P2
P0
23
145665
)7)(2()8)(7()13)(5(
y
y
y
m
m
m
)(
1
0
)( inexti
N
i
inextiy xxzzm
![Page 27: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/27.jpg)
Newell Method for Normal Vectors
Calculate z component of normal
416
211
907
416
zyx
P0
P1
P2
P05
1061
)2)(5()1)(6()1)(1(
z
z
z
m
m
m
)(
1
0
)( inexti
N
i
inextiz yyxxm
Note: Using Newell method yields same result as
Cross product method (2,-23,-5)
![Page 28: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/28.jpg)
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
mar
mer
mae
2
Θ1 Θ2
Note: Θ1 = Θ2
![Page 29: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/29.jpg)
Forms of Equation of a Line
Two-dimensional forms of a line Explicit: y = mx +h
Implicit: ax + by +c =0
Parametric:
x(a) = ax0 + (1-a)x1
y(a) = ay0 + (1-a)y1
Parametric form of line More robust and general than other forms
Extends to curves and surfaces
Po
P1
α
Pα
1 - α
![Page 30: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/30.jpg)
Convexity
An object is convex iff for any two points in the object all points on the straight line between these points are also in the object
P
Q Q
P
convexnot convex
![Page 31: Prof Emmanuel Agu - web.cs.wpi.eduweb.cs.wpi.edu/~emmanuel/courses/cs543/f18/slides/lecture03c.pdf7 0 9 6 1 4 x y z P0 P1 P2 P0 5 1 6 10 ( 1)(1) (6 )(1) ( 5)( 2) z z z m m m 1 ( )](https://reader036.vdocuments.site/reader036/viewer/2022062605/5fc8c16f2ce2da3e7e24f131/html5/thumbnails/31.jpg)
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