3d geometry for computer graphics class 1. general office hour: tuesday 11:00 – 12:00 in schreiber...

49
3D Geometry for Computer Graphics Class 1

Post on 22-Dec-2015

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

3D Geometry forComputer Graphics

Class 1

Page 2: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

General

Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance)

Webpage with the slides, homework: http://www.cs.tau.ac.il/~sorkine/courses/cg/cg2006/

E-mail: [email protected]

Page 3: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

The plan today

Basic linear algebra and Analytical geometry

Page 4: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Why??

Page 5: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Manipulation of geometry and color…

Monsters, Inc

Page 6: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Manipulation of geometry and color…

Page 7: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Manipulation of geometry and color…

Page 8: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Manipulation of geometry and color…

Page 9: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Manipulation of geometry and color…

Page 10: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Why??

We represent objects using mainly linear primitives: points lines, segments planes, polygons

Need to know how to compute distances, transformations, projections…

Page 11: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

How to approach geometric problems

We have two ways:1. Employ our geometric intuition

2. Formalize everything and employ our algebra skills

Often we first do No.1 and then solve with No.2 For complex problems No.1 is not always

easy…

Page 12: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Example: distance between 2 lines in 3D

Geometric problem: we have two lines (or segments) in 3D, need to find the distance between them

two_lines.exe

Page 13: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Example: distance between 2 lines in 3D

Geometric approach: If we look from the direction of one of the lines, that

line reduces to a point So all we need is point-line distance in 2D (the

projection plane) By projecting, we reduced the problem from 3D to 2D

Page 14: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Example: distance between 2 lines in 3D

Geometric approach: We can continue reducing the dimension! Project the red point and the blue line on the plane

perpendicular to the blue line Now we get point-point distance

Page 15: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Example: distance between 2 lines in 3D

But how do we get the actual number? Need to represent the lines mathematically

OK…

Write down the projection formulae Have to wipe the dust off our algebra…

Compute the point-point distance Easy

Page 16: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Example: distance between 2 lines in 3D

Alternative: (Almost) skip the geometric intuition step… Represent the lines mathematically We know that the distance is achieved at a segment

that is perpendicular to both lines Write down the equation for that segment and solve

2

2

( ), || || , 0

( ), , || || 0

s t

s t

1 2

1 2

p p u u v u

p p v u v v

Page 17: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Conclusion so far:

With or without geometric intuition and good 3D orientation, in any case we need to

review our algebra…

Page 18: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Basic definitions

Points specify location in space (or in the plane). Vectors have magnitude and direction (like

velocity).

Points Vectors

Page 19: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Point + vector = point

Page 20: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

vector + vector = vector

Parallelogram rule

Page 21: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

point - point = vector

A

BB – A

A

BA – B

Page 22: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

point + point: not defined!!

Page 23: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Map points to vectors

If we have a coordinate system with

origin at point O We can define correspondence between points

and vectors:

p p p O

v O + v

O

p

Page 24: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Inner (dot) product

Defined for vectors:

, || || || || cosθ v w v w

L v

wL

cosθ || ||

,

|| ||L

w

v w

v

Projection of w onto v

Page 25: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Dot product in coordinates (2D)

v

w

xv

yv

xw

yw

x

y

O

( , )

( , )

,

v v

w w

v w v w

x y

x y

x x y y

v

w

v w

Page 26: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Perpendicular vectors

v

v

, 0

( , ) ( , )v v v vx y y x

v w

v vIn 2D only:

Page 27: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Distance between two points

B

A

xB

yB

xA

yA

x

y

O

22 )()(

,

||||),(dist

ABAB yyxx

ABAB

ABBA

Page 28: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Parametric equation of a line

p0

vt > 0

t < 0 t = 0

( ) , ( , )t t t 0p v

Page 29: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Parametric equation of a ray

p0

vt > 0

t = 0

( ) , (0, )t t t 0p v

Page 30: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

2

22 2 2

2

, 0

( ), 0

, , 0

, ,

, || ||

,dist ( , ) || || || ||

|| ||

t

t

t

l

0

0

0 0

00

q q v

q p v v

q p v v v

q p v q p v

v v v

q p vq q q q p

v

Distance between point and line

Find a point q’ such that (q q’)vdist(q, l) = || q q’ ||

p0

v

q

q’ = p0 +tv

l

Page 31: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Easy geometric interpretation

p0

v

q

q’2 2 2

2 2 2

22

2

:

(1) dist( , ) || ||

,(2)

|| ||

dist( , ) || ||

,|| || .

|| ||

L

L

L

0

0

0

00

Pythagoras

q q q p

q p v

v

q q q p

q p vq p

v

l

L

Page 32: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Distance between point and line – also works in 3D!

The parametric representation of the line is coordinates-independent

v and p0 and the checked point q can be in 2D or in 3D or in any dimension…

Page 33: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Implicit equation of a line in 2D

0, , , R, ( , ) (0,0)Ax By C A B C A B

x

yAx+By+C > 0

Ax+By+C < 0

Ax+By+C = 0

Page 34: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Line-segment intersection

1 2

1 1 2 2

The segment Q Q intersects the line

( )( ) 0Ax By C Ax By C

x

yAx+By+C > 0

Ax+By+C < 0

Q1 (x1, y1)

Q2 (x2, y2)

Page 35: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Representation of a plane in 3D space

A plane is defined by a normal n and one point in the plane p0.

A point q belongs to the plane < q – p0 , n > = 0

The normal n is perpendicular to all vectors in the plane

n

p0

q

Page 36: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Distance between point and plane

Project the point onto the plane in the direction of the normal:

dist(q, ) = ||q’ – q||

n

p0q’

q

Page 37: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Distance between point and plane

n

p0q’

q

2

22 2 2 2

2

( ) || , R

, 0 (because is in the plane )

, 0

, , 0

,

|| ||

,dist ( , ) || || || || .

|| ||

0

0

0

0

0

q q n q q n q q n

q p n q

q n p n

q p n n n

p q n

n

q p nq q q n

n

Page 38: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Distance between point and plane

Geometric way: Project (q - p0) onto n!

n

p0

q

0| , |dist

q p n

n

Page 39: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Implicit representation of planes in 3D

0, , , , R, ( , , ) (0,0,0)Ax By Cz D A B C D A B C

(x, y, z) are coordinates of a point on the plane (A, B, C) are the coordinates of a normal vector to the

plane

Ax+By+Cz+D > 0

Ax+By+Cz+D < 0

Ax+By+Cz+D = 0

Page 40: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Distance between two lines in 3D

p1

p2

u

v

d

The distance is attained between two points q1 and q2

so that (q1 – q2) u and (q1 – q2) v

q1

q2

l1

l2

1

2 2

( )

( )

l s s

l t t

1p u

p v

Page 41: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Distance between two lines in 3D

( ) , 0

( ) , 0

s t

s t

1 2

1 2

p p u v u

p p u v v

2

2

( ), || || , 0

( ), , || || 0

s t

s t

1 2

1 2

p p u u v u

p p v u v v

p1

p2

u

v

d

q1

q2

l1

l2

1

2 2

( )

( )

l s s

l t t

1p u

p v

Page 42: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Distance between two lines in 3D

2

2 2 2

2

2 2 2

, , || || ,

|| || || || ,

|| || , , ,

|| || || || ,

s

t

1 2 1 2

1 2 1 2

u v v p p v u p p

u v u v

u u p p u v u p p

u v u v

p1

p2

u

v

d

q1

q2

l1

l2

1

2 2

( )

( )

l s s

l t t

1p u

p v

Page 43: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Distance between two lines in 3D

||)~()~(||),(dist 2121 tlslll

p1

p2

u

v

d

q1

q2

l1

l2

1

2 2

( )

( )

l s s

l t t

1p u

p v

Page 44: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Distance between two lines in 3D

Exercise (תרגיל רשות): Develop the distance formula using the geometric

intuition we talked about in the beginning of the class Compare to the formula we’ve just developed

analytically

Page 45: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

See you next time!

Page 46: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Barycentric coordinates (2D)

Define a point’s position relatively to some fixed points. P = A + B + C, where A, B, C are not on one line, and

, , R. (, , ) are called Barycentric coordinates of P with

respect to A, B, C (unique!) If P is inside the triangle, then ++=1, , , > 0

A B

C

P

Page 47: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Barycentric coordinates (2D)

A B

C

P

triangletheofareathedenotes,,

,,

,,

,,

,,

,,

,,

CCBA

BAPB

CBA

ACPA

CBA

CBPP

Page 48: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Example of usage: warping

Page 49: 3D Geometry for Computer Graphics Class 1. General Office hour: Tuesday 11:00 – 12:00 in Schreiber 002 (contact in advance) Webpage with the slides, homework:

Example of usage: warping

Tagret

AB

C

We take the barycentric coordinates , , of P’ with respect to A’, B’, C’.Color(P) = Color( A + B + C)

PP

1P