Analytic surfaces are smooth, differentiable surfaces that are described by a mathematical equation (or set of equations). In many cases, the easiest surfaces to find normals for are analytic surfaces for which you have an explicit definition in the following form:
V(s,t) = [ X(s,t) Y(s,t) Z(s,t) ]
where s and t are constrained to be in some domain, and X, Y, and Z are differentiable functions of two variables. To calculate the normal, find
![[IMAGE]](figures/eqapf01.gif)
which are vectors tangent to the surface in the s and t directions. The cross product
![[IMAGE]](figures/eqapf02.gif)
is perpendicular to both, and hence to the surface. The following shows how to calculate the cross product of two vectors. (Watch out for the degenerate cases where the cross product has zero length!)
![[IMAGE]](figures/eqapf03.gif)
You should probably normalize the resulting vector. To normalize a vector [x,y,z], calculate its length
![[IMAGE]](figures/eqapf04.gif)
and divide each component of the vector by the length.
As an example of these calculations, consider the analytic surface
V(s,t) = [ s2 t3 3-st ]
From this we have
![[IMAGE]](figures/eqapf05.gif)
So, for example, when s=1 and t=2, the corresponding point on the surface is (1, 8, 1), and the vector (-24, 2, 24) is perpendicular to the surface at that point. The length of this vector is 34, so the unit normal vector is (-24/34, 2/34, 24/34) = (-0.70588, 0.058823, 0.70588).
For analytic surfaces that are described implicitly, as F(x, y, z) = 0, the problem is harder. In some cases, you can solve for one of the variables, say z = G(x, y), and put it in the explicit form given previously:
![[IMAGE]](figures/eqapf06.gif)
Then continue as described earlier.
If you can't get the surface equation in an explicit form, you might be able to make use of the fact that the normal vector is given by the gradient
![[IMAGE]](figures/eqapf07.gif)
evaluated at a particular point (x, y, z). Calculating the gradient might be easy, but finding a point that lies on the surface can be difficult. As an example of an implicitly defined analytic function, consider the equation of a sphere of radius 1 centered at the origin:
x2 + y2 + z2 - 1 = 0
This means that
F(x, y, z) = x2 + y2 + z2 - 1
which can be solved for z to yield
![[IMAGE]](figures/eqapf08.gif)
Thus, normals can be calculated from the explicit form
![[IMAGE]](figures/eqapf09.gif)
as described previously.
If you could not solve for z, you could have used the gradient
![[IMAGE]](figures/eqapf10.gif)
as long as you could find a point on the surface. In this case, it's not so hard to find a point - for example, (2/3, 1/3, 2/3) lies on the surface. Using the gradient, the normal at this point is (4/3, 2/3, 4/3). The unit-length normal is (2/3, 1/3, 2/3), which is the same as the point on the surface, as expected.
OpenGL Programming Guide