CS184 Lecture 18 summary

Curved Lines and Surfaces

So far we have several types of user-defined shapes:

But all of these are different flavors of collections of straight lines or flat polygons. The basic shapes like sphere and cylinder are also implemented with a set of flat faces in a Browser-specific way.

Clearly these shapes are a poor approximation to true curved shapes. They suffer from:

Now we consider representations that allow truly smooth shapes. They are based on the use of smooth functions.

There are two basic kinds of representation for curved objects. In a parametric representation, points on the curve or surface are given as functions of one or more parameters. In an implicit representation, the curve or surface is defined to be the set of points that satisfy one or more equation(s).

Parametric Curves

The general form of a parametric curve is

x = f(s)
y = g(s)
z = h(s)

where f, g, h are smooth functions and s is the parameter.

Example

The parametric curve defined by

x = cos s
y = - sin s
z = s

Is a spiral pointing along the z-direction. You can think of the s-value, which is unique on each point on the curve, as defining a coordinate along the curve.

Parametric curves are by far the most common representation used.

Implicit Curves

An implicit curve is the set of points which satisfy two equations:

f(x, y, z) = 0               g(x, y, z) = 0

Example

The equations:

x2 + y2 = 1                   z = 3

defines a circle with unit radius centered at the point (0, 0, 3).

Implicit curves are rarely seen, except as intersection curves of implicit surfaces.

Parametric Surfaces

A parametric surface has the representation:

x = f(s, t)
y = g(s, t)
z = h(s, t)

Example

x = cos s
y = - sin s
z = t

defines a cylinder with unit radius centered along the z-axis.

Parametric surfaces are the most widely used today.

Implicit Surfaces

An implicit surface has the representation

f(x, y, z) = 0

Example

x2 + y2 + z2= 1

defines a unit sphere centered at the origin.

Implicit surfaces are not very common in modelers today, although they do have certain advantages. It is much easier to intersect two implicit surfaces exactly (to get an implicit representation for the intersection curve, you simply grab the equations for each of the surfaces), and their complexity (algebraic degree) is lower for a given modeling accuracy.

The main reason implicit surfaces are not as widely used is that it is harder to control their shape. As we will see, parametric surfaces can be fitted with "handles" that allow fairly direct manipulation of their shape.

Aside: Trigonometric vs. rational parametrization

In practice, most modelers can't handle curves or surfaces defined with trig functions like sin and cos. They are designed for polynomial or rational functions (a rational function is simply a quotient of two polynomial functions). Luckily you can always make a parameter substitution that eliminates the sin and cos.

Consider the function

u = tan s/2

which is single-valued over the range - p to p.

Recall some trigonometric identities:

sec s = 1/cos s

tan2 s = sec2 s - 1

sin 2s = 2 sin s cos s

cos 2s = 2 cos2 s - 1

Now

sin s = 2 sin s/2 cos s/2
         = 2 tan s/2 cos2 s/2
         = 2 tan s/2 / sec2 s/2
         = 2 tan s/2 / (1 + tan2 s/2)

sin s = 2 u / (1 + u2)

and

cos s = 2 cos2 s/2 - 1
          = 2 / sec2 s - 1
          = 2 / (1 + tan2 s/2) - 1
          = (1 - tan2 s/2) / (1 + tan2 s/2)

cos s = (1 - u2) / (1 + u2)

So using the substitution s = 2 arctan u (or u = tan s/2), we can eliminate both sin and cos from a parametrization, and produce a purely rational one.

Note: if s itself appears in the parametrization, as is the case for the spiral, we cannot do this.

Example

The unit sphere can be parametrized as

x = cos s cos t
y = - sin s cos t
z = sin t

where s and t correspond respectively to longitude and latitude. We use the above substitutions s = 2 arctan u,    t = 2 arctan v     and obtain

x = [(1 - u2)(1 - v2)] / [(1 + u2)(1 + v2)]

y = [-2 u (1 - v2)] / [(1 + u2)(1 + v2)]

z = 2v / (1 + v2)

which is a purely rational parametrization for the sphere.

Normals and Tangents

We can obtain normal and tangent information from parametric and implicit formulae by taking derivatives.

Tangents to a parametric surface

To compute the tangents to a parametric surface, we compute derivatives. One tangent is the vector:

(df/ds, dg/ds, dh/ds)

while the other is

(df/dt, dg/dt, dh/dt)

Example

For the parametric sphere, the s tangent is

(-sin s cos t, -cos s cos t, 0)

while the t tangent is

(- cos s sin t, sin s sin t, cos t)

and these tangents lie along a line of latitude and a line of longitude respectively.

Normal to an implicit surface

To get the normal to the implicit surface

f(x, y, z) = 0

we compute

(df/dx, df/dy, df/dz)

which is the gradient of the function. To see that this is the normal, recall that the directional derivative of a function along some direction v is

v . grad(f)

Now take v to be any tangent direction to the surface. Since the surface is defined by f = 0, the function value does not change along a tangent. Therefore v . grad(f) = 0 for any tangent to the surface. Since grad(f) has zero dot product with (i.e. is orthogonal to) all the tangents to the surface, it must be normal to the surface.

Example

The implicit sphere:

x2 + y2 + z2= 1

The gradient of this function is

(2x, 2y, 2z)

and you can check that this vector is normal to any point on the sphere (it is a vector from the origin to any point).