CSE 409 - 2011.11.15 TUE

advertisement
Vector Tools for
Computer Graphics
Computer Graphics
Vector Tools for Computer Graphics

Two branches of Mathematics



Vector Analysis
Transformation
Why Vectors?
Basic Definitions


Points specify location in space (or in the plane).
Vectors have magnitude and direction (like
velocity).
Points  Vectors
Basics of Vectors
v
P
Vector as displacement:
v
v is a vector from point P to point Q.
Q
The difference between two points is a vector: v = Q - P
Another way:
The sum of a point and a vector is a point : P + v = Q
P
Q
v
Operations on Vectors
Two operations
Addition
Multiplication be scalars
a+b
sa
a = (3,5,8), b = (-1,2,-4)
a = (3,-5,8), s = 5
a + b = (2,7,4)
5a = (15,-25,40)
operations are done componentwise
Operations on vectors
Addition
b
a+ b
a+ b
a
a
Multiplication by scalar
a
2a
-a
b
Operations on vectors
Subtraction
a-c
a
a
c
-c
a-c
a
c
Linear Combination of Vectors
Definition
Linear combination of m vectors v1, v2, …, vm:
w = a1v1 + a2 v2 + …+ amvm
where a1,a2,…am are scalars.
Types
Affine Combination
Convex Combination
a1 + a2 + …+ am = 1
a1 + a2 + …+ am = 1
Examples:
and ai ≥ 0, for i = 1,…m.
3a + 2b - 4c
(1- t)a + (t)b
Example: .3a + .2b + .5c
Convex Combination of Vectors
v2
a(v2-v1)
v
v3
v1
v2
v1
Properties of vectors
Length or size
w = (w1,w2,…,wn)
2
2
2
|w
|w

w

...

w
1
2
n
Unit vector

a
a
a
• The process is called normalizing
• Used to refer direction
The standard unit vectors: i = (1,0,0), j = (0,1,0) and k = (0,0,1)
Dot Product
The dot product d of two vectors v = (v1,v2,…,vn)
and w = (w1,w2,…wn):
Properties
1. Symmetry: a·b = b·a
2. Linearity: (a+c) ·b = a·b + c·b
3. Homogeneity: (sa) ·b = s(a·b)
4. |b|2 = b·b
Application of Dot Product
Angle between two vectors:
y
c
b
Φc
^
^
cos(
)bc
θ
Φb
x
Two vectors b and c are perpendicular (orthogonal/normal) if
b·c = 0
2D “perp” Vector
Which vector is perpendicular to the 2D vector a = (ax,ay)?
a┴
a
Let a = (ax,ay).
Then
a┴ = (-ay,ax)
is the
counterclockwise
perpendicular to a.
-a┴
a
What about 3D case?
Applications: Orthogonal Projection
C
C
c
A
L
c
Mv┴
v
Kv
v┴
v
A
Applications: Reflections
n
n
a
a
r
θ1
θ2
r
m
-m
e
r = a - 2 ( a . n) n
e
Cross Product


Also called vector product.
Defined for 3D vectors only.
i j k
ab ax ay az
bx by bz
Properties
1. Antisymmetry: a Χ b = - b Χ a
2. Linearity: (a +c) Χ b = a Χ b + c Χ b
3. Homogeneity: (sa) Χ b = s(a Χ b)
Geometric Interpretation of Cross Product
y
axb
a
P3
P1
b
P2
x
z
1. aXb is perpendicular to both a and b
2. | aXb | = area of the parallelogram defined by a and b
Representation of
Vectors and Points
Coordinate Frame
b
P
v
O
c
a
Homogeneous Representation


Basic objects: a,b,c,O
Represent points and vectors using these objects
Homogeneous Representation
To go from ordinary to homogeneous
1.If point append 1 as the last coordinate.
2.If vector append 0 as the last coordinate.
To go from homogeneous to ordinary
1.The last coordinate must be made 1 and then delete it
2.The last coordinate must be made 0 and then delete it
Linear Combinations of vectors
The difference of two points is a vector
The sum of a point and vector is a point
The sum of two vectors is a vector
The scaling of a vector is a vector
Any linear combination of vectors is a vector
Affine Combinations of Points
Two points P=(P1,P2,P3,1) and R=(R1,R2,R3,1):
E = fP + gR=(fP1+gR1, fP2+gR2, fP3+gR3, f+g)
Since affine combination so f+g=1
So, E is a valid point in homogeneous representation
NOT a valid point, unless f + g = 1
Example: 0.3P+0.7R is a valid point, but P + R is not.
any affine combination of points is a legitimate point
Linear Combinations of Points
Linear combination of two points P and R:
E = fP + gR
If the system is shifter by U
P’ = P + U
R’ = R + U
E’ should be equal to E+U i.e E’=E+U
E should also be shifted by U
But,
E’ = fP’ + gR’ = fP + gR + (f+g)U
NOT, unless f + g = 1
Affine Combinations of Points [contd]
P1+P2
P1
P1+P2
(P1+P2)/2
P2
Point + Vector = Affine Comb of Points
Let,
P = A + t v and v = B – A
Therefore,
P = A + t (B – A)
=> P = t B + (1 – t) A.
“Tweening”
Linear Interpolation
See Hill 4.5.4
Representing Lines
Line
Line segment
3 types of representations:
1. Two point form
2. Parametric representation
3. Point normal form
Ray
Parametric Representation of a Line
y
t>1
b
B
t=1
C
t=0
t<0
x
Point Normal Form of a Line
n
B
R
C
All in One : Representations of Line
B = C - n┴
{C, B}
Point
Normal
Two Point
n = (B – C) ┴
Parametric
{C, b}
{C, n}
Planes in 3D

3 fundamental forms



Three-point form
Parametric representation
Point normal form
Parametric Representation of Plane
b
C
a
Point Normal Form of a Plane
n
B
All in One : Representations of Plane
A=(0,0,n.C/ nz)
B=(0,n.C/ ny,0)
{A,C,B}
Three Point
n = (A-C)x(B – C)
Parametric
{C, a, b}
C=(C-0)
Point
Normal
{C, n}
Readings

Hill 4.1 – 4.6
Download