**Generating the torus and helitoroid**

A parametric representation of a torus:

$$\begin{array}{l}\overrightarrow{T}(u,v)=(\mathrm{cos}(u)(R+r\mathrm{sin}(v)),\text{}\mathrm{sin}(u)(R+r\mathrm{sin}(v)\text{})\text{,}r\mathrm{cos}(v)),\\ \text{for}0\le \text{}u\text{}\le \text{}2\pi \text{,}0\le \text{}v\text{}\le \text{}2\pi \end{array}$$ $$\begin{array}{l}\\ \text{}\end{array}\begin{array}{l}\\ \text{inwhich}\overrightarrow{T}(u,v)\text{isthepositionvectorofageneralpointonthesurface,}\\ \text{}R\text{isthemajorradiusofthetorus,}\\ \text{}r\text{istheminorradius,i}\text{.e}\text{.,theradiusofthetube}\text{.}\end{array}$$

This torus is in a standard position, but we can move it to different positions or orientations in space by applying coordinate transformations.

I begin the construction of the helitoroid with the parametric definition of a directrix curve:

$$\begin{array}{l}\overrightarrow{h}(u)=R(\mathrm{cos}(u),\text{}\mathrm{sin}(u),\text{}0)\text{}\text{}+\text{}r(\text{}\mathrm{sin}(Wu)\mathrm{cos}(u),\text{}\mathrm{sin}(Wu)\mathrm{sin}(u),\text{}\mathrm{cos}(Wu)),\\ \text{for}0\le \text{}u\text{}\le \text{}2\pi \end{array}$$

in which *W* is a positive integer, which I call the *winding*.
This curve moves at constant distance *r* from the major circle, which is the circle of radius *R* in the plane *z*=0, centered at the origin, and it closes on its tail after winding around the major circle *W* times.

As for any smooth space curve, we get the tangent vector $\widehat{t}(u)$
to the directrix curve at any point as the unit vector in the direction of the derivative of the position vector with respect to the parameter.
$$\begin{array}{l}\dot{\overrightarrow{h}}(u)=\frac{d}{du}\overrightarrow{h}(u)\\ \widehat{t}(u)=\dot{\overrightarrow{h}}(u)/\Vert \dot{\overrightarrow{h}}(u)\Vert \end{array}$$

The dots on top mean derivative. The hat on
$\widehat{t}(u)$
signifies unit vector. $\Vert \Vert $ means length of vector.

The derivative of the tangent vector is perpendicular to it. (Exercise for the reader: convince yourself from elementary vector calculus definitions that the derivative of a unit vector function is perpendicular to it.)

So we let

$$\begin{array}{l}\dot{\widehat{t}}(u)=\frac{d}{du}\widehat{t}(u)\\ \widehat{n}(u)=\dot{\widehat{t}}(u)/\Vert \dot{\widehat{t}}(u)\Vert \end{array}$$

The unit vector
$\widehat{n}(u)$
is called the *normal vector to the curve*. The plane through the point $\overrightarrow{h}(u)$
spanned by
$\widehat{t}(u)$ and
$\widehat{n}(u)$
is called the *osculating plane*. The projection of the space curve on the osculating plane is the plane curve that best approximates the space curve in a small neighborhood of
$\overrightarrow{h}(u)$
.

So $\widehat{t}(u)$ and $\widehat{n}(u)$ are two perpendicular unit vectors. Their cross product

$$\widehat{b}(u)=\widehat{t}(u)\times \widehat{n}(u)$$

is called the curve *binormal* and
$\{\widehat{t}(u)\text{,}\widehat{n}(u)\text{,}\widehat{b}(u)\}$
form an orthonormal frame, which moves along the curve with the parameter $u$, and is called the *Frenet frame*. This frame is the context for the beautiful theory of smooth space curves. See the books by Dirk Struik or Barrett O'Neill for good introductions (Chapter 1 in both).

The vectors $\widehat{n}(u)\text{and}\widehat{b}(u)$ span the plane through the point that's perpendicular to the tangent of the directrix curve . I generate my helitoroid surface by inflating the directrix curve to a tube of cross section radius $\rho $ . For any given point $\overrightarrow{h}(u)$ on the directrix curve, the points on the circle of radius $\rho $ about $\overrightarrow{h}(u)$ in the plane perpendicular to the directrix curve are parameterized by

$$\begin{array}{l}\overrightarrow{H}(u,v)\text{}=\text{}\overrightarrow{h}(u)\text{}+\text{}\rho (\mathrm{cos}(v)\text{}\widehat{n}(u)\text{}+\text{}\mathrm{sin}(v)\text{}\widehat{b}(u))\\ \text{for}0\text{}\le \text{}v\text{}\le \text{}2\pi \end{array}$$

Thus, letting $u$ vary over its full range, we get the (doubly) parametric representation of the helitoroid surface :

$$\begin{array}{l}\overrightarrow{H}(u,v)\text{}=\text{}\overrightarrow{h}(u)\text{}+\text{}\rho (\mathrm{cos}(v)\text{}\widehat{n}(u)\text{}+\text{}\mathrm{sin}(v)\text{}\widehat{b}(u))\\ \text{for}0\le u\le 2\pi ,\text{}0\text{}\le \text{}v\text{}\le \text{}2\pi \end{array}$$

For any values of the two parameters, the quantities on the right can be calculated from the original definition of $\overrightarrow{h}(u)$ and the formulas of elementary vector calculus. You can see the code that implements them in the JavaScript. Note that there are a lot of terms that come from evaluating the first and second derivatives, and substantial computing for the cross products and the normalizations. Note how much more compact and intuitive than the code is this presentation in vector math notation.

The tessellation of each of these surfaces is obtained by evaluating the position vectors on an integer lattice in the 2D parameter domain, and the quads thus formed are bisected to form triangles. The two surfaces in the current example comprise 12000 triangles.

Also, for the smooth shading I need normal vectors to the both surfaces at each vertex of the tessellations. Symmetry considerations show that the helitoroid surface normal at each point is

$$\mathrm{cos}(v)\text{}\widehat{n}(u)+\mathrm{sin}(v)\text{}\widehat{b}(u)$$

and the torus surface normal at each point is

$$(\mathrm{cos}(u)\mathrm{sin}(v),\text{}\mathrm{sin}(u)\mathrm{sin}(v),\text{}\mathrm{cos}(v))$$

which both are computed in the course of computing the vertex positions.