math primer for cg

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

Upload: cliff

Post on 06-Feb-2016

41 views

Category:

Documents


0 download

DESCRIPTION

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. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Math Primer for CG

Math Primer for CG

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

Page 2: Math Primer for CG

Contents

Scalar, Vector, PointChange of BasisFrameChange of FrameAffine Sum, Convex Combination, Convex Hull, …Case Study: shooting game

Page 3: Math Primer for CG

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…

Page 4: Math Primer for CG

Scalars: Live in Real Space

Two fundamental operations are defined between pairs: Addition,

multiplication ClosureS, S, ·S

SCommutative

··

Associative····

Distributive···

Additive & multiplicative inverse·

Page 5: Math Primer for CG

Real Analysis

The study of real numbers…If you are interested, see Analysis WebNotes:

http://www.math.unl.edu/~webnotes/contents/chapters.htm

Page 6: Math Primer for CG

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

Page 7: Math Primer for CG

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

Page 8: Math Primer for CG

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

Page 9: Math Primer for CG

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

Page 10: Math Primer for CG

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

Page 11: Math Primer for CG

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

Page 12: Math Primer for CG

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

Page 13: Math Primer for CG

Summary: Mathematical Spaces

Real Space(Scalar)

Vector Space(Scalar, Vector)

Euclidean Space(Scalar, Vector)

[distance]

Affine Space(Scalar, Vector, Point)

[location]

Page 14: Math Primer for CG

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

Page 15: Math Primer for CG

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

Page 16: Math Primer for CG

Convex Hull

Page 17: Math Primer for CG

Now, how to apply these math

Besides change of basis/frame…

Page 18: Math Primer for CG

Ex: Parametric Equation of a Line

Q

R

S() 10 ,)1()( RQS

Q

R

S() RRQS ,)1()(

Page 19: Math Primer for CG

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

Page 20: Math Primer for CG

Ex: Homogeneous Coordinates

A unified representation scheme in affine space for points and vectorsChange of Frame: subsume change of basis

Page 21: Math Primer for CG

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]

Page 22: Math Primer for CG

Ex: Shooting (AABB)

Intersection can be checked using 3D Sutherland algorithm

0p

0p

Page 23: Math Primer for CG

Cohen-Sutherland Line-Clipping Algorithm

Trivially acceptTrivially rejectclipping

Page 24: Math Primer for CG

Ex: Shooting (OBB)

Change of frame then apply Sutherland algorithm in the local frame

0p

0p

Page 25: Math Primer for CG

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

Page 26: Math Primer for CG

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

Page 27: Math Primer for CG

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

Page 28: Math Primer for CG

Exercise

Convex Hull: prove convex combination yields the shape you imagine