Formula for Torus' top half:
z = Sqrt(- x^2 - y^2 + Sqrt(x^2 + y^2) + R
Without R, this will generate a torus of outer radius one and inside "hole" of radius zero (it's just pinched at the origin). Adding the R value will scale both the torus' outer radius and the radius of its hole equally but oppositely. Bigger R means bigger hole, but smaller torus, and vice versa. Values of R betweem 0 and 1/4 are acceptable. (Why 0 and 1/4? When you hit 1/4, which is actually treated as Sqrt(1/4) (notice the whole expression is under a Sqrt), you have created a hole with 1/2 radius, but shrunk the torus' outer radius to 1/2... a cylinder.) More elucidation forthcoming.
Donuts [5k] : donut excursion (grafx removed) Donuts II [93k] : excursion in 2d (grafx present) DonutFun [4k] : manipulations (grafx removed) Tori I [2,500k] : tori excursion (grafx present) Tori II [4,381k] : manipulations (grafx present)