math primer for cg ref: interactive computer graphics, chap. 4, e. angel

28
Math Primer for CG Ref: Interactive Computer Graphics, Chap. 4, E. Angel

Upload: anthony-cox

Post on 26-Dec-2015

224 views

Category:

Documents


1 download

TRANSCRIPT

Math Primer for CG

Ref: Interactive Computer Graphics, Chap. 4, E. Angel

Contents

Scalar, Vector, PointChange of BasisFrameChange of FrameAffine 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 ClosureS, S, ·S

SCommutative

··

Associative····

Distributive···

Additive & multiplicative inverse·

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 Closureu,vV, u+vV

Commutativeu+v=v+u

Associative u+(v+w)=(u+v)+w

Distributive (u+v)=u+v )u=u+u

Vector Space (cont)

Linear combinationu=1u1+2u2+…+nun

Linear independentOnly set of scalars such th

atu=1u1+2u2+…+nun

is zero 1=2=…=n=0

Basis a set of linearly indepen

dent vectors that span the space

Vector Space: change of basis

represent any vector uniquely in a basis

change of basis

332211 uuuu

3

2

1

321

uuuu

3332321313

3232221212

3132121111

vvvu

vvvu

vvvu

332313

322212

312111

321321

vvvuuu

3

2

1

321332211

vvvvvvu

3

2

1

3

2

1

332313

322212

312111

3

2

1

321

3

2

1

332313

322212

312111

321

vvvvvv

Example

3

2

1

3

2

1

321 eeeu

3213

212

11

1

1

1

0

1

1

0

0

1

eeev

eev

ev

100

110

011

100

110

111

100

110

111

321

1

321321

321321

vvv

vvveee

eeevvv

3

1

1

3

2

1

100

110

011

321321 vvvvvvu

New Basis

Points: Live in Affine SpaceVector 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 framesRepresent point in a frame

Change of frame

0332211 PuuuP

0332211 QvvvP

03432421410

3332321313

3232221212

3132121111

QvvvP

vvvu

vvvu

vvvu

100043332313

42322212

41312111

03210321

QvvvPuuu

1110003

2

1

03213

2

1

43332313

423222112

413121111

0321

QvvvQvvv

1110003

2

1

3

2

1

43332313

423222112

413121111

1110003

2

1

3

2

1

43332313

423222112

413121111

Euclidean Space

Supplement vector space with the notion of distanceNew operation Inner (dot)

product

S u,v,wVu · v=v · u(u+v) · w=u · w + v ·

wv · v>0 (v0)0 · 0=0u · v=0 u and v are ortho

gonal|v|=(v · v)½

u · v=|u||v| cos

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:

QRP

QRQvQP

)1(

)(

1 where 2121 QRP

Q

R

P()Point addition is allowed only if their weights add up to one

Affine Sum (cont)More generally,

Convex Combination A particular affine sum where weights are non-n

egative

1 where i

ii

iiPP 1 where i

ii

iiPP

0 and 1 where ii

ii

iiPP 0 and 1 where ii

ii

iiPP

Convex Hull

Now, how to apply these math

Besides change of basis/frame…

Ex: Parametric Equation of a Line

Q

R

S() 10 ,)1()( RQS

Q

R

S() RRQS ,)1()(

Ex: Plane, Triangle, Parallelogram

Q

R

S()P

T()

10 ,10 ,10

10 and 10

,

R

u

v

RQP

PRPQP

vuPT

PRvPQu

)1(

)()(

),(

;

(infinite) Plane

Parallelogram

Triangle

Ex: Homogeneous Coordinates

A unified representation scheme in affine space for points and vectorsChange 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

0332211 PuuuP

13

2

1

0321

PuuuP

03

2

1

0321

Puuuu

Point: [1 2 3 1]Frame: [u1 u2 u3 P0]

Vector: [1 2 3 0]Frame: [u1 u2 u3 P0]

Ex: Shooting (AABB)

Intersection can be checked using 3D Sutherland algorithm

0p

0p

Cohen-Sutherland Line-Clipping Algorithm

Trivially acceptTrivially rejectclipping

Ex: Shooting (OBB)

Change of frame then apply Sutherland algorithm in the local frame

0p

0p

Ex: Ray-Triangle Intersection

),,(t for triple ),()(

Solve

10 ,10 ,10

,)1(),(

Triangle

0,)(

:Ray

210

0

tqtp

qqqq

tutptp

u

v

w

0p

0q

1q

2q

Ex: Shooting (discrete version)

v

w

0p0q

0p

),,(t for triple ),()(

Solve

10,10,10

,)1(),(

Triangle

)1()(

:PathBullet

)( );(

210

00

0000

tqtp

qqqq

ptpttp

ttpptpp

Ex: Shooting (continuous version)

0p

0p0q

0q

2q

1q

2q

1q

),,(t for triple ),,()(

Solve

10 ,10 ,10

)1()(

)1()(

)1()(

)()()()1(),(

:motion)(in Triangle

10 ,)1()(

:PathBullet

,,; :)(After

,,; :)( Before

222

111

000

210

00

21000

21000

ttqtp

qtqttq

qtqttq

qtqttq

tqtqtqq

tptpttp

qqqptt

qqqpt

Exercise

Convex Hull: prove convex combination yields the shape you imagine