Computing the topological genus from a parametric function

Recall that the topological genus of a surface (or Euler characteristic) is (in essence) the number of its "holes." Thus the genus of a baseball is 0 while the genus of a donut or handled coffee cup is 1.

Is there a way to calculate the topological genus of surfaces defined by a parametric function? For instance, in this case:

ParametricPlot3D[
{Cos[θ] + .4 Cos[θ] Sin[φ], Sin[θ] + .4 Sin[θ] Sin[φ], Cos[φ]},
{θ, 0, 2 π}, {φ, 0, 2 π}]


the answer is genus = 1, while in this case:

ParametricPlot3D[{Cos[θ] Sin[φ], 2 Sin[θ] Sin[φ], Cos[φ]},
{θ, 0, 2 π}, {φ, 0, π}]


the answer is genus = 0.

I searched for methods based on RegionFunction but found nothing quite right.

• Yes! Quite astoundingly there is a way to do just that. Have a look at the Gauss-Bonnet Theorem. You can implement this by finding the Gaussian curvature for your surface parametrisation and integrating it over the whole surface via Integrate or NIntegrate. Apr 26 '17 at 18:45

Integrating the Gauss curvature as suggested in the comments is possible, but horrible (it is a rather complicated function of the parameters, and I would not trust Mathematica to do it right). A better solution is to use Morse Theory. Namely, pick "height function" (the $x$ coordinate might work, but a random linear combination of the three coordinates will work better), compute the critical points of this function (as a function of the parameter), and then use Morse's formula for the Euler characteristic:
$$\chi(M) = \sum_\gamma (-1)^\gamma C_\gamma,$$ where $C_\gamma$ is the number of critical points of index $\gamma$ - in this case, $\gamma$ is one of $0, 1, 2,$ and the three kinds of critical points correspond to maxima, minima, and saddles. In particular, if you take the $x$ coordinate for your first surface, the "Morse function" is
$$\frac{2}{5} \cos (\theta) \sin (\phi)+\cos (\theta).$$ Its critical points are:
$$\left\{\left\{\theta\to 0,\phi\to \frac{\pi }{2}\right\},\left\{\theta\to 0,\phi\to \frac{3 \pi }{2}\right\},\left\{\theta\to \pi ,\phi\to \frac{\pi }{2}\right\},\left\{\theta\to \pi ,\phi\to \frac{3 \pi }{2}\right\}\right\},$$ and the values of the function are $$\frac75, \frac35, -\frac35, -\frac75.$$ The outside ones are a maximum and minimum respectively, the middle one are saddles, for $\chi = 0,$ as expected. (Recall that $\chi(M) = 2 - 2 g.)$