i
i
i
i
i
i
i
i
2.5. Curves and Surfaces 31
p when dotted with itself has value r
2
.” Because a vector dotted with itself is just
its own length squared, we could also read the equation as, “points p on the circle
have the following property: the vector from c to p has squared length r
2
.”
Even better, is to observe that the squared length is just the squared distance
from c to p, which suggests the equivalent form
p − c
2
− r
2
=0,
and, of course, this suggests
p − c−r =0.
The above could be read “the points p on the circle are those a distance r from
the center point c,” which is as good a definition of circle as any. This illustrates
that the vector form of an equation often suggests more geometry and intuition
than the equivalent full-blown Cartesian form with x and y. For this reason, it
is usually advisable to use vector forms when possible. In addition, you can
support a vector class in your code; the code is cleaner when vector forms are
used. The vector-oriented equations are also less error prone in implementation:
once you implement and debug vector types in your code, the cut-and-paste errors
involving x, y,andz will go away. It takes a little while to get used to vectors in
these equations, but once you get the hang of it, the payoff is large.
2.5.2 The 2D Gradient
If we think of the function f(x, y) as a height field with height = f(x, y),the
gradient vector points in the direction of maximum upslope, i.e., straight uphill.
The gradient vector ∇f(x, y) is given by
∇f(x, y)=
∂f
∂x
,
∂f
∂y
.
The gradient vector evaluated at a point on the implicit curve f(x, y)=0is
perpendicular to the tangent vector of the curve at that point. This perpendicular
vector is usually called the normal vector to the curve. In addition, since the
gradient points uphill, it indicates the direction of the f(x, y) > 0 region.
In the contextof height fields, the geometric meaning of partial derivatives and
gradients is more visible than usual. Suppose that near the point (a, b), f(x, y) is
Figure 2.24. Asurface
height =
f
(
x,y
) is locally pla-
nar near (
x,y
)=(
a,b
). The
gradient is a projection of
the uphill direction onto the
height = 0 plane.
a plane (Figure 2.24). There is a specific uphill and downhill direction. At right
angles to this direction is a direction that is level with respect to the plane. Any
intersection between the plane and the f(x, y)=0plane will be in the direction
that is level. Thus the uphill/downhill directions will be perpendicular to the line
of intersection f(x, y)=0. To see why the partial derivative has something to do