Generating the torus and helitoroid

A parametric representation of a torus:

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:

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 $\stackrel{^}{t}\left(u\right)$ 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. $h → ˙ (u)= d du h → (u) t ^ (u)= h → ˙ (u)/‖ h → ˙ (u) ‖$
The dots on top mean derivative. The hat on signifies unit vector. $‖‖$ 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

$t ^ ˙ ( u ) = d d u t ^ ( u ) n ^ ( u ) = t ^ ˙ ( u ) / ‖ t ^ ˙ ( u ) ‖$

The unit vector $\stackrel{^}{n}\left(u\right)$ is called the normal vector to the curve.   The plane through the point $\stackrel{\to }{h}\left(u\right)$  spanned by $\stackrel{^}{t}\left(u\right)$ and $\stackrel{^}{n}\left(u\right)$  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 $\stackrel{\to }{h}\left(u\right)$ .

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

$b ^ ( u ) = t ^ ( u ) × n ^ ( u )$

is called the curve binormal and 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 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 $\stackrel{\to }{h}\left(u\right)$ on the directrix curve, the points on the circle of radius $\rho$ about $\stackrel{\to }{h}\left(u\right)$ in the plane perpendicular to the directrix curve are parameterized by

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

For any values of the two parameters, the quantities on the right can be calculated from the original definition of $\stackrel{\to }{h}\left(u\right)$ 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

and the torus surface normal at each point is

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