Download Computer Graphics (CS 543) Lecture 4(Part 2): Linear Algebra for

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
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 coordinate system
Example: Point (5,4)
y
(5,4)
(0,0)
x
Vectors





Magnitude
Direction
NO position
Can be added, scaled, rotated
CG vectors: 2, 3 or 4 dimensions
Length
Angle
Points



Location in coordinate system
Cannot add or scale
Subtract 2 points = vector
Point
Vector‐Point Relationship


Diff. b/w 2 points = vector
v = Q – P
point + vector = point
v + P = Q
P
v
Q
Vector Operations

Define vectors
a  (a1, a2 , a3 )
b  (b1,b2 , b3 )
Then vector addition:
a  b  (a1  b1, a2  b2 , a3  b3 )
a
a+b
b
Vector Operations


Define scalar, s
Scaling vector by a scalar
as  (a1s, a2 s, a3 s )
Note vector subtraction:
ab
 (a1  (b1 ), a2  (b2 ), a3  (b3 ))
a
a-b
a
2.5a
b
Vector Operations: Examples

Scaling vector by a scalar
as  (a1s, a2 s, a3 s )

•Vector addition:
a  b  (a1  b1, a2  b2 , a3  b3 )
For example, if a=(2,5,6) and b=(‐2,7,1)
and s=6, then
a  b  (a1  b1, a2  b2 , a3  b3 )  (0,12,7)
as  (a1s, a2 s, a3 s )  (12,30,36)
Affine Combination

Given a vector a  (a1, a2 , a3 ,..., an )


a1  a2  .........an  1
Affine combination: Sum of all components = 1
Convex affine = affine + no negative component
i.e
a1 , a2 ,.........an  non  negative
Magnitude of a Vector

Magnitude of a
2
2
| a | a1  a2 ..........  an

2
Normalizing a vector (unit vector)
a
vector
â  
a magnitude

Note magnitude of normalized vector = 1. i.e
2
2
2
a1  a2 ..........  an  1
Magnitude of a Vector

Example: if a = (2, 5, 6)

Magnitude of a

Normalizing a
| a | 2 2  52  6 2  65
5
6 
 2
â  
,
,

 65 65 65 
Convex Hull


Smallest convex object containing P1P2,…..Pn
Formed by “shrink wrapping” points
12
Dot Product (Scalar product)

Dot product,
d  a  b  a1  b1  a2  b2 ........  a3  b3

For example, if a=(2,3,1) and b=(0,4,‐1)
then
a b  (2  0)  (3  4)  (1 1)
 0  12  1  11
Properties of Dot Products

Symmetry (or commutative):
a b  b a

Linearity:
(a  c)  b  a  b  c  b

Homogeneity:
( sa)  b  s (a  b)

And
b2  b  b
Angle Between Two Vectors
y
b   b cos b , b sin b 
c
c

b
c   c cos c , c sin c 
b  c  b c cos
b
x
b
b
b
Sign of b.c:
c
b.c > 0
c
b.c = 0
c
b.c < 0
Angle Between Two Vectors

Find the angle b/w the vectors b = (3,4) and c = (5,2)
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
b̂   , 
5 5
  31.326
bˆ  cˆ  0.85422  cos
Standard Unit Vectors
y
Define
i  1,0,0
j  0,1,0 
k  0,0,1
So that any vector,
i
k
0
z
v  a, b, c   ai  bj  ck
j
x
Cross Product (Vector product)
If
a  a x , a y , a z 
b  bx , by , bz 
Then
a  b  (a y bz  a z by )i  (a x bz  a z bx ) j  (a x by  a y bx )k
Remember using determinant
i
ax
bx
Note: a x b is perpendicular to a and b
j
ay
by
k
az
bz
Cross Product
Note: a x b is perpendicular to both a and b
axb
a
0
b
Cross Product
Calculate a x b if a = (3,0,2) and b = (4,1,8)
Cross Product
Calculate a x b if a = (3,0,2) and b = (4,1,8)
a x b = -2i – 16j + 3k
Normal for Triangle using Cross Product Method
n
plane
p2
n·(p - p0 ) = 0
n = (p2 - p0 ) ×(p1 - p0 )
normalize n  n/ |n|
p
p1
p0
Note that right‐hand rule determines outward face
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
p1
p0

p2
Proposed by Martin Newell at Utah (teapot guy)



Uses formulae, suitable for computer
Compute during mesh generation
Robust!
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 - P0
P2
(1,1,2)
PO
(6,1,4)
P1 (7,0,9)
Newell Method for Normal Vectors

Formulae: Normal N = (mx, my, mz)
N 1
mx    yi  ynext ( i ) zi  z next (i ) 
i 0
N 1
m y   zi  z next (i ) xi  xnext (i ) 
i 0
N 1
mz   xi  xnext (i )  yi  ynext (i ) 
i 0
Using Newell method, for previous example plug in values result is same:
Normal is (2, -23, -5)
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
r  em
 r  a  2m
m
Θ1
e
-m
Θ2
e
Lines

Consider all points of the form


P()=P0 +  d
Line: Set of all points that pass through P0 in direction of vector d
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


α
P1
1-α
Po
More robust and general than other forms
Extends to curves and surfaces
Pα
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
convex
Q
not convex
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(, )
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
Related documents