Download Three basic (data) types in CG: scalars, points, and vectors

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
Math Primer for CG
Ref: Interactive Computer
Graphics, Chap. 4, E. Angel
Contents
Scalar, Vector, Point
Change of Basis
Frame
Change of Frame
Affine Sum, Convex Combination,
Convex Hull, …
Case Study: shooting game
Introduction
Three basic data types in CG: scalars, points,
and vectors



scalar: not a geometric type per se; used in
measurement
point: a location in space; exist regardless of any
coordinate system
vector: any quantity with direction and magnitude;
does not have fixed location
Examine these concepts in a mathematically
more rigorous way…
Scalars: Live in Real Space
Two fundamental
operations are
defined between
pairs:
Addition,
multiplication
 Closure
a,bS,
a+bS, a·bS

a,b,gS
Commutative
a+b=b+a
a · b=b · a
Associative
a ·(b · g)=(a · b) · g
a+(b+g)=(a+b)+g
Distributive
a ·(b+g)=(a · b)+(a · g)
Additive & multiplicative
inverse
a+(-a)=0, a · a-1=1
Real Analysis
The study of real numbers
…
If you are interested, see Analysis
WebNotes:
http://www.math.unl.edu/~webnotes/contents/chapters.htm
Vectors: Live in Vector Space
Two kinds of entities:

Scalar, vector
Two operations and
corresponding
geometric
interpretations:
v-v addition
(head-tail)
 scalar-v multiplication
(scaling of vector)
Properties


Closure
u,vV, u+vV
Commutative
u+v=v+u

Associative
 u+(v+w)=(u+v)+w


Distributive
 a(u+v)=au+av
 (a+b)u=au+bu
Vector Space (cont)
Linear combination
u=a1u1+a2u2+…+anun
Linear independent
Only set of scalars such
that
u=a1u1+a2u2+…+anun
is zero
 a1=a2=…=an=0
Basis

a set of linearly
independent vectors that
span the space
Vector Space: change of basis
represent any vector
uniquely in a basis
u1

u2

 
u3  = v1 v2
a11 a 21 a 31 

v3 a12 a 22 a 32 
a13 a 23 a 33 




u = a1u1 + a 2u2 + a 3u3
  
u = u1 u 2




 
u = b1v1 + b 2v2 + b 3v3 = v1 v2
a1 

u3 a 2 
a 3 
change of basis




u1 = a11v1 + a12v2 + a13v3




u2 = a 21v1 + a 22v2 + a 23v3




u3 = a 31v1 + a 32v2 + a 33v3
v1

v2
 b1 

v3  b 2 
 b 3 
a11 a 21 a 31  a1 

 
v3 a12 a 22 a 32  a 2  = v1 v2
a13 a 23 a 33  a 3 
a11 a 21 a 31  a1   b1 
a
 a  =  b 
a
a
12
22
32

 2   2 
a13 a 23 a 33  a 3   b 3 
 b1 

v3  b 2 
 b 3 
Example
1

 
u = 2 = e1 e2
3
1 

e3 2
3
v1

v2
-1
e1

e2
New Basis
1

  
v3 = 1 = e1 + e2 + e3
1

 
e3  = v1 v2
 
= v1 v2
1


v1 = 0 = e1
0
1

 
v2 = 1 = e1 + e2
0

 
v3  = e1 e2
1 1 1

e3 0 1 1
0 0 1
  
u = v1 v2
1 1 1

v3 0 1 1
0 0 1
1 - 1 0 

v3 0 1 - 1
0 0 1 
1 - 1 0  1

 
v3 0 1 - 1 2 = v1 v2
0 0 1  3
- 1

v3 - 1
 3 
Points: Live in Affine Space
Vector space lacks

Location, distance, …
Concept of coordinate
system (frame)


Reference point: origin
Frame: origin + basis
defines position in space
Add another entity to
vector spaces

Point
New operations


Point – Point  Vector
Point + Vector  Point
(translation)
Note that the following
are not defined:


point addition
multiplication of scalar &
point
Affine Space: change of frames



P = b1v1 + b 2v2 + b 3v3 + Q0
Represent point in a
frame



P = a1u1 + a 2u2 + a 3u3 + P0
u1
u2
Change of frame




u1 = a11v1 + a12v2 + a13v3




u2 = a 21v1 + a 22v2 + a 23v3 v1 v2




u3 = a 31v1 + a 32v2 + a 33v3



P0 = a 41v1 + a 42v2 + a 43v3 + Q0
v3
u3
P0  = v1 v2
v3
a11 a 21 a 31 a 41 
a

a
a
a
12
22
32
42

Q0 
a13 a 23 a 33 a 43 


0
0
0
1


a11 a 211 a 31 a 41  a1 
a
 a 
a
a
a
12
221
32
42
  2  = v1 v2
Q0 
a13 a 23 a 33 a 43  a 3 

 
0
0
1  1 
0
a11 a 211 a 31 a 41  a1   b1 
a
 a   b 
a
a
a
12
221
32
42

 2  =  2 
a13 a 23 a 33 a 43  a 3   b 3 

   
0
0
0
1

 1   1 
v3
 b1 
b 
Q0  2 
 b3 
 
1
Euclidean Space
Supplement vector
space with the
notion of distance
New operation

Inner (dot) product
a,bS u,v,wV
u · v=v · u
(au+bv) · w=au · w + bv ·
w
v · v>0 (v0)
0 · 0=0
u · v=0  u and v are
orthogonal
|v|=(v · v)½
u · v=|u||v| cosq
Summary: Mathematical Spaces
Real Space
(Scalar)
Vector Space
(Scalar, Vector)
Euclidean Space
(Scalar, Vector)
[distance]
Affine Space
(Scalar, Vector, Point)
[location]
Affine Sum
In affine space, point addition is only
defined in the following case:

P = Q + av = Q + a ( R - Q)
P = aR + (1 - a )Q
P = a1R + a 2Q where a1 + a 2 = 1
Point addition is allowed
only if their weights add
up to one
Q
R
P(a)
Affine Sum (cont)
More generally,
P = a i Pi where a i = 1
i
i
Convex Combination
 A particular affine sum where weights are nonnegative
P = a i Pi where a i = 1 and a i  0
i
i
Convex Hull
Now, how to apply these math
Besides change of basis/frame…
Ex: Parametric Equation of a Line
R
S (a ) = aQ + (1 - a ) R, a  R
S(a)
Q
R
Q
S(a)
S (a ) = aQ + (1 - a ) R, 0  a  1
Ex: Plane, Triangle, Parallelogram

u  Q - P;

v  R-P


T (a , b ) = P + au + bv
R

v
P
T(a,b)

u
S(a)
= P + a (Q - P) + b ( R - P)
Q
= (1 - a - b ) P + aQ + bR
(infinite) Plane
a, b  R
Parallelogram
0  a  1 and 0  b  1
Triangle
0  a  1, 0  b  1, 0  a + b  1
Ex: Homogeneous Coordinates
A unified representation scheme in
affine space for points and vectors
Change of Frame: subsume change of
basis
Affine Space: coordinate
system
fixing the origin of the
vectors of coordinate
system at P0
4x1 “vector”:

Unified vector & point
representation
homogeneous
coordinate


distinguish point & vector
4x4 matrix algebra for
change in frames



P = a1u1 + a 2u2 + a 3u3 + P0
 
P = u1 u2

u3
Point: [a1 a2 a3 1]
Frame: [u1 u2 u3 P0]
  
u = u1 u2

u3
Vector: [a1 a2 a3 0]
Frame: [u1 u2 u3 P0]
a1 
a 
P0  2 
a 3 
 
1
a1 
a 
P0  2 
a 3 
 
0
Ex: Shooting (AABB)
p0
p0
Intersection can be
checked using 3D
Sutherland
algorithm
Cohen-Sutherland Line-Clipping Algorithm
Trivially accept
Trivially reject
clipping
Ex: Shooting (OBB)
p0
p0
Change of frame
then apply
Sutherland
algorithm in the
local frame
Ex: Ray-Triangle Intersection
Ray :

w
q0

v

p (t ) = p0 + tu , t  0
q2
Triangle

u
q1
q (a , b ) = (1 - a - b )q0 + aq1 + bq2 ,
p0
0  a  1, 0  b  1, 0  a + b  1
Solve
p (t ) = q (a , b ) for triple t (t , a , b )
Ex: Shooting (discrete version)
p0 = p(t0 ); p0 = p (t0 + t )
Bullet Path :

w
q0

v
p(t ) = (1 - t ) p0 + tp0
p0
Triangle
p0
q (a , b ) = (1 - a - b )q0 + aq1 + bq2 ,
0  a  1,0  b  1,0  a + b  1
Solve
p(t ) = q (a , b ) for triple t (t , a , b )
Ex: Shooting (continuous version)
Before (t0 ) : p0 ; q0 , q1 , q2
After (t0 + t ) : p0 ; q0 , q1, q2
Bullet Path :
p (t ) = (1 - t ) p0 + tp0 , 0  t  1
q2
q0
p0
q2
Triangle (in motion) :
p0
q0
q1
q1
q (a , b ) = (1 - a - b )q0 (t ) + aq1 (t ) + bq2 (t )
q0 (t ) = (1 - t )q0 + tq0
q1 (t ) = (1 - t )q1 + tq1
q2 (t ) = (1 - t )q2 + tq2
0  a  1, 0  b  1, 0  a + b  1
Solve
p (t ) = q (a , b , t ) for triple t (t , a , b )
Exercise
Convex Hull: prove convex combination
yields the shape you imagine
Related documents