The torus is perhaps the least used object in real modelling applications but it still appears as a standard form in modelling and rendering packages ahead of far more useful geometric primitives. In any case, given the conventions below, that is, defining the radius (r0) from the center to the middle of the ring of the torus and the radius (r1) of the cross section of ring of the torus.
|
The points on the torus are defined as
x = cos(theta) * [ r0 + r1 * cos(phi) ] y = sin(theta) * [ r0 + r1 * cos(phi) ] z = r1 * sin(phi) Or in an implicit form z2 + (sqrt(x2 + y2) - a)2 - b2 = 0 |
where theta and phi range from 0 to 2pi. Using the above formulation a torus with center radius r0 = 1 and outer radius r1 = 0.25 will look something like this

The code for generating a facet approximation to a torus as described later involves creating facets with vertices defined by
|
theta,phi theta + dtheta,phi theta + dtheta,phi + dphi theta,phi + dphi |
If a facet approximation to a torus is required then a large number of facets are generally necessary to produce a smooth rendered surface. In the wire frame example above dphi and dtheta were 10degrees, this results in 36x36=1296 facets.
Another approach is to create a torus from a number of spheres which rendering packages often support more efficiently. This is achieved by simply packing spheres around a circular path, radius r0. The radius of the sphere being the radius r1. For example, the following shows the same torus dimension as in the earlier example created with 50 and 100 spheres.

C Source
This C code generated the facet representation shown above, the planar facets are exported in DXF for this example.
Supertoroid - A Geometric Primitive for Computer Aided Design
|
The supertoroid is a family of geometric primitives based on the torus.
Let r0 the radius of the inner ring r1 the radius of the outer ring as illustrated below where theta and phi range from 0 to 2pi.
The equation for the supertoroid is the same as that for the torus except that the sin and cosine terms are raised to powers.
|
|
It is different values of these powers which give rise to a family of 3D shapes all basically toroidal in shape. The value of n1 determines the shape of the torus ring, n2 determines the shape of the cross section of the ring.
Examples of the supertoroid generated for different values of n1 and n2 are shown below, of course, the legal values of n1 and n2 form a continuum of values from 0 to infinity (although there are representation issues near 0 and above 4).

An idea of the continuum of cross sectional shapes offered by squaring the sin() and cosine() terms consider the following

C source
Code which generates a facet based supertoroid in DXF format is given here. (Written for clarity not efficiency).