3D Geometry for Computer Graphics

advertisement

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: http://www.cs.tau.ac.il/~sorkine/courses/cg/cg2006/

 E-mail: sorkine@tau.ac.il

The plan today

 Basic linear algebra and

 Analytical geometry

Why??

Manipulation of geometry and color…

Monsters, Inc

Manipulation of geometry and color…

Manipulation of geometry and color…

Manipulation of geometry and color…

Manipulation of geometry and color…

Why??

 We represent objects using mainly linear primitives:

 points

 lines, segments

 planes, polygons

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

How to approach geometric problems

1.

We have two ways:

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…

Example: distance between 2 lines in 3D

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

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

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

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

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



( p p ), u

1

2

 

 

( p p ), v

1

2 s || u ||

2 s u v

 

 

0 t || v ||

2 

0

Conclusion so far:

 With or without geometric intuition and good 3D orientation, in any case we need to review our algebra…

Basic definitions

 Points specify location in space (or in the plane).

 Vectors have magnitude and direction (like velocity).

Points  Vectors

Point + vector = point

vector + vector = vector

Parallelogram rule

point - point = vector

A

A

B

B

point + point: not defined!!

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

   v

O + v

O

Inner (dot) product

 Defined for vectors:

L

 w

   v

|| v || || w

 cos θ

L

L

|| v ||

Projection of w onto v

Dot product in coordinates (2D) y y w y v w

O x w v x v v w

 x y v v

)

( x , y w w

)

  x x v w

 y y v w x

Perpendicular vectors

In 2D only:

 v

 

0 x y v v

)

 v

( y x v v

) v

 v

Distance between two points y y

A y

B

O x

A

A x

B

B x dist ( A , B )

|| B

A ||

 

B

A , B

A

 

( x

B

 x

A

)

2 

( y

B

 y

A

)

2

Parametric equation of a line

 p t v , t

0

( , ) p

0 v

Parametric equation of a ray

 p t v , t

0

 

(0, ) p

0 v

Distance between point and line

Find a point q’ such that ( q

 q’ )

 v dist(q, l) = || q

 q’ ||

  

, v

 

0 t

 

( p

0

 t v ), v

 

0

, v

 

0 t v v

 

 

, v

0

 v v

|| v ||

2

0 q p , v

0

 p

0 v

2 q l

 q q

||

2 

|| q p

0

||

2 

 

, v

0

|| v ||

2

 2 q l q

= p

0

+tv

Easy geometric interpretation

Pythagoras :

(1)

(2)

L 2  q q

) 2 

||

0

|| 2

L

 

, v

0

|| v ||

|| q q q p

0

||

)

2

2 

||

||

2

0

 

0

, v

|| v ||

2

 2

.

q p

0 v

L q’ l

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

 The parametric representation of the line is coordinates-independent

 v and p

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

Implicit equation of a line in 2D

Ax

By C 0, , ,

A B

(0, 0) y

Ax+By+C > 0

Ax+By+C < 0 x

Line-segment intersection y

The segment Q Q intersects the line

1 2

( Ax

1

By

1

)(

2

By

2

C )

0

Q

1

( x

1

, y

1

)

Ax+By+C > 0

Q

2

( x

2

, y

2

)

Ax+By+C < 0 x

Representation of a plane in 3D space

A plane

 is defined by a normal n and one point in the plane p

0

.

A point q belongs to the plane

< q – p

0

, n > = 0

The normal n is perpendicular to all vectors in the plane n q p

0

Distance between point and plane

 Project the point onto the plane in the direction of the normal: dist( q,

) = ||q’ – q|| n q q’ p

0 

Distance between point and plane

( q

  q ) || n

 q

    n , q p , n

0

 

   

0

, n

0 q

 

0

 

 

 

0

 p ,

0

 n

2

 n n

 

0

 

R

2 q

)

|| q

  q ||

2  

2

 q

  n

2 

 

0

, n n

2

 2

.

 n q n q’ p

0 

Distance between point and plane

 Geometric way:

 Project ( q p

0

) onto n !

dist

|

 

0

,

| n q n p

0 

Implicit representation of planes in 3D

Ax

By

Cz D 0, , , ,

A B C

(0, 0, 0)

(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

Distance between two lines in 3D l s

1

( ) l t

2

 p s u

1

 p t v

2

 l

1 l

2 d q

1 q

2 p

1 u v p

2

The distance is attained between two points q

1 so that ( q

1

– q

2

)

 u and ( q

1

– q

2

)

 v and q

2

Distance between two lines in 3D l s

1

( ) l t

2

 p s u

1

 p t v

2

 l

2

(

( p p

1

1

 p p

2

2

)

)

 s s u u

 t t

,

,



0



0 l

1 d q

1 p

1 u v p

2 q

2



( p p ), u

1

2

 

 

( p p ), v

1

2 s || u ||

2 s u v

 

 

0 t || v ||

2 

0

Distance between two lines in 3D l s

1

( ) l t

2

 p s u

1

 p t v

2

 l

1 d q

1 p

1 u v p

2 l

2 q

2 t s

,

 

, u

1

 v p

||

2

2

 

 

|| v ||

2  u p

1

 p

2

 2 u

2  u p

1

 p

2

   u

2 v ||

2  

,

 

,

1

 p

2

 2

Distance between two lines in 3D l s

1

( ) l t

2

 p s u

1

 p t v

2

 l

2 l

1 d q

1 q

2 p

1 u v p

2 dist ( l

1

, l

2

)

|| l

1

( s )

 l

2

( t

~

) ||

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

See you next time!

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

C

P

A B

Barycentric coordinates (2D)

P

P , B , C

A

P , C , A

B

P , A , B

A , B , C A , B , C A , B , C

,

,

 denotes the area of the triangle

C

C

P

A B

Example of usage: warping

Example of usage: warping

C

P

P

Tagret P

1

A

B

We take the barycentric coordinates

,

,

 of P’ with respect to A’, B’, C’ .

Color( P ) = Color(

A +

B +

C )

Download