3D Geometry Representation for Computer Graphics

30
3D Geometry Representation for Computer Graphics November 3, 2016

Transcript of 3D Geometry Representation for Computer Graphics

Page 1: 3D Geometry Representation for Computer Graphics

3D Geometry Representation

for Computer Graphics

November 3, 2016

Page 2: 3D Geometry Representation for Computer Graphics

Outline

• Implicit vs. parametric equations for surfaces

• Surface normals

• Surface types discussed in this lecture

– Plane

– Quadrics: Sphere, ellipsoid, cylinder, cone, etc.

– Toroid

– Superquadric

– Supertoroid

Page 3: 3D Geometry Representation for Computer Graphics

Sphere

Implicit equation for sphere centered at origin:

3D point (x,y,z) is on, outside, or inside sphere:

Parametric equation for sphere:

f (x, y, z) = x2 + y2 + z2 − r2

ϕ

θϕ

θϕ

sin

sincos

coscos

rz

ry

rx

=

=

= −π

2≤ φ ≤

π

2

−π ≤θ ≤ π

f (x, y, z) = 0 f (x, y, z) < 0f (x, y, z) > 0

Page 4: 3D Geometry Representation for Computer Graphics

Sphere

Parametric equation, rewritten in vector form:

p(u, v) =

r cosucosv

r cosusin v

rsinu

1

−π

2≤ u ≤

π

2

−π ≤ v ≤ π

Page 5: 3D Geometry Representation for Computer Graphics

Parametric Surface Equations

• Parametric form is good for generating triangle mesh

• The (u,v) parameters of each vertex can be used for applying a 2D texture map to the surface

Texture maps from:

http://www.robinwood.com/Catalog/FreeStuff/Textures/TexturePages/BallMaps.html

Page 6: 3D Geometry Representation for Computer Graphics

Ellipsoid

Implicit equation for ellipsoid centered at origin:

Parametric equation for ellipsoid:

f (x, y, z) = xrx

( )2

+ y

ry( )2

+ zrz

( )2

−1

p(u, v) =

rx cosucosv

ry cosusin v

rz sinu

1

−π

2≤ u ≤

π

2

−π ≤ v ≤ π

Page 7: 3D Geometry Representation for Computer Graphics

Implicit Equation: Quadric Form

Implicit equation for general quadric surface can be

written in terms of symmetric matrix Q:

Equivalent to:

xTQx = 0 Q =

A B C D

B E F G

C F H I

D G I J

x =

x

y

z

1

f (x, y, z) = Ax2 + 2Bxy + 2Cxz + 2Dx + Ey2 + 2Fyz + 2Gy + Hz2 + 2Iz + J = 0

Page 8: 3D Geometry Representation for Computer Graphics

Sphere

Implicit equation:

Equivalent to:

xTQx = 0

Q =

A B C D

B E F G

C F H I

D G I J

=

1 0 0 0

0 1 0 0

0 0 1 0

0 0 0 −r2

=

1

r2

0 0 0

01

r2

0 0

0 01

r2

0

0 0 0 −1

x =

x

y

z

1

f (x, y, z) = Ax2 + 2Bxy + 2Cxz + 2Dx + Ey

2 + 2Fyz + 2Gy + Hz2 + 2Iz + J = 0

f (x, y, z) = x2 + y

2 + z2 − r

2

f (x, y, z) =x

2

r2

+y

2

r2

+z

2

r2

−1

Page 9: 3D Geometry Representation for Computer Graphics

Ellipsoid

Implicit equation:

Equivalent to:

xTQx = 0

Q =

A B C D

B E F G

C F H I

D G I J

=

1

rx

20 0 0

01

ry

20 0

0 01

rz

20

0 0 0 −1

f (x, y, z) = Ax2 + 2Bxy + 2Cxz + 2Dx + Ey

2 + 2Fyz + 2Gy + Hz2 + 2Iz + J = 0

f (x, y, z) =x

2

rx

2+

y2

ry

2+

z2

rz

2−1

Page 10: 3D Geometry Representation for Computer Graphics

Cylinder Implicit Equation

Infinite cylinder (along z axis), elliptical cross-section:

Equivalent to:

xTQx = 0

Q =

A B C D

B E F G

C F H I

D G I J

=

1

rx

20 0 0

01

ry

20 0

0 0 0 0

0 0 0 −1

f (x, y, z) = Ax2 + 2Bxy + 2Cxz + 2Dx + Ey

2 + 2Fyz + 2Gy + Hz2 + 2Iz + J = 0

f (x, y, z) =x

2

rx

2+

y2

ry

2−1

Page 11: 3D Geometry Representation for Computer Graphics

Parametric Surface Equations

Ellipsoid:

Cylinder with elliptical cross-section:

umin ≤ u ≤ umax

−π ≤ v ≤ πp(u, v) =

rx cosv

ry sin v

u

1

−π

2≤ u ≤

π

2

−π ≤ v ≤ πp(u, v) =

rx cosucosv

ry cosusin v

rz sinu

1

Page 12: 3D Geometry Representation for Computer Graphics

Cone Implicit Equation

Infinite cone (along z axis), elliptical cross-section:

Equivalent to:

xTQx = 0

Q =

A B C D

B E F G

C F H I

D G I J

=

1

rx

20 0 0

01

ry

20 0

0 0 −1

s2

0

0 0 0 0

f (x, y, z) = Ax2 + 2Bxy + 2Cxz + 2Dx + Ey

2 + 2Fyz + 2Gy + Hz2 + 2Iz + J = 0

f (x, y, z) =x

2

rx

2+

y2

ry

2−

z2

s2

Page 13: 3D Geometry Representation for Computer Graphics

Parametric Surface Equation

Cone with elliptical cross-section:

umin ≤ u ≤ umax

−π ≤ v ≤ πp(u, v) =

urx cosv

ury sin v

u

1

Page 14: 3D Geometry Representation for Computer Graphics

Plane Implicit Equation

Given plane equation

Equivalent to:

xTQx = 0

Q =

A B C D

B E F G

C F H I

D G I J

=

0 0 0a

2

0 0 0b

2

0 0 0c

2

a

2

b

2

c

2−d

f (x, y, z) = Ax2 + 2Bxy + 2Cxz + 2Dx + Ey

2 + 2Fyz + 2Gy + Hz2 + 2Iz + J = 0

f (x, y, z) = ax + by + cz − d

ax + by + cz − d = 0

Page 15: 3D Geometry Representation for Computer Graphics

Parametric Plane Equation

There are a number of ways to parameterize a plane surface. One is to use basis vectors u, v and origin p0

Basis vectors u v are orthogonal in this case.

p(u, v) = p0 + uu + vv

p(u, v) =

x0

y0

z0

1

+ u

xu

yu

zu

0

+ v

xv

yv

zv

0

p0

v

u

Page 16: 3D Geometry Representation for Computer Graphics

Quadric Surfaces

See wikipedia page for more examples

Page 17: 3D Geometry Representation for Computer Graphics

Torus

Implicit equation for torus with circular cross-section

centered at origin:

Parametric equation:

f (x, y, z) = x2 + y2 − raxial( ) + z2 − r2

p(u, v) =

(raxial + r cosu)cosv

(raxial + r cosu)sin v

rsinu

1

−π ≤ u ≤ π

−π ≤ v ≤ π

Page 18: 3D Geometry Representation for Computer Graphics

Varying the Radius: raxial

Page 19: 3D Geometry Representation for Computer Graphics

Superquadric Ellipsoids

Page 20: 3D Geometry Representation for Computer Graphics

Superquadric Ellipsoids

Implicit equation:

Parametric equation:

f (x, y, z) = xrx

( )2

ε2 + y

ry( )2

ε2

ε2

ε1

+ zrz

( )2

ε1 −1

p(u, v) =

rx sign(cosu) cosuε1

sign(cosv) cosvε2

ry sign(cosu) cosuε1

sign(sin v) sinvε2

rz sign(sinu) sinuε1

1

−π

2≤ u ≤

π

2,−π ≤ v ≤ π

ε1 > 0,ε2 > 0

ε1 = ε2 =1 is ellipsoid

ε1 = ε2 = 0.1 is box-like shape

Page 21: 3D Geometry Representation for Computer Graphics

Supertoroids!

Page 22: 3D Geometry Representation for Computer Graphics

Supertoroid

Implicit equation:

Parametric equation:

f (x, y, z) = xrx

( )2

ε2 + y

ry( )2

ε2

ε2

2

− raxial

2

ε1

+ zrz

( )2

ε1 −1

p(u, v) =

rx sign(cosu) cosuε1

raxial + sign(cosv) cosvε2( )

ry sign(cosu) cosuε1

raxial + sign(sinv) sin vε2( )

rz sign(sinu) sinuε1

1

−π ≤ u ≤ π,−π ≤ v ≤ π

Page 23: 3D Geometry Representation for Computer Graphics

Computing Surface Normals

Page 24: 3D Geometry Representation for Computer Graphics

Surface Normal

• Surface normal at each vertex can be used in

illumination and shading of the mesh.

Page 25: 3D Geometry Representation for Computer Graphics

Surface Normal

• Advanced topic: Surface normals are also used in game

physics and animation: computing collision response,

friction, etc., where surfaces are in contact.

Page 26: 3D Geometry Representation for Computer Graphics

Computing the Surface Normal

• Parametric form:

– Take partial derivative (tangent to surface) along each

parametric direction.

– Cross-product yields the normal.

• Use 3D (non-homogeneous form), for instance sphere:

n(u, v) =∂

∂up(u, v) ⊗

∂vp(u, v)

p(u, v) =

r cosucosv

r cosusin v

rsinu

Page 27: 3D Geometry Representation for Computer Graphics

Computing Sphere Surface Normal

n(u, v) =∂

∂u

r cosucosv

r cosusinv

rsinu

⊗∂

∂v

r cosucosv

r cosusinv

rsinu

n(u, v) =

−rsinucosv

−rsinusinv

r cosu

−r cosusinv

r cosucosv

0

n(u, v)

|| n(u, v) ||=

cosucosv

cosusinv

sinu

Page 28: 3D Geometry Representation for Computer Graphics

Computing Surface Normal

from Implicit Equation

• Given the implicit equation for a surface, we can

obtain the normal at (x,y,z) by taking the gradient:

n(x, y, z) = ∇f (x, y, z)

n(x, y, z) =

∂xf (x, y, z)

∂yf (x, y, z)

∂zf (x, y, z)

Page 29: 3D Geometry Representation for Computer Graphics

Computing Sphere Surface Normal

from Implicit Equation

Given a point on surface

n(x, y, z) = ∇f (x, y, z)

n(x, y, z) =

∂xx

2 + y2 + z

2 − r2( )

∂yx

2 + y2 + z

2 − r2( )

∂zx

2 + y2 + z

2 − r2( )

=

2x

2y

2z

f (x, y, z) = x2 + y

2 + z2 − r

2 = 0

Page 30: 3D Geometry Representation for Computer Graphics

Quadric Surface Normal

from Implicit Equation

Given a point x on surface

n(x) = ∇ xTQx( )n(x) = 2Qx

xTQx = 0