It's not a homework question. I stopped using pimple cream decades ago. Nor have I enrolled in an Open University course for Seniors.

I'll have to come clean! After nearly 30 years as a policeman, I'm retired now and can engage my mind in solving the really important questions in policing. This thread is about solving the First World policing problem: "How many doughnuts can you get into a pizza box?"

Obviously there is too much wasted space if you try to pack round doughnuts (which are an example of the Torus, a 3D object). My researches lead me to this website http://paulbourke.net/geometry/torus/ where I found the answer to part of my problem - the square doughnut.

According to the author, the general formula for a torus is:



where
ro is the radius of a circle midway between the inner and outer edges of the doughnut.
theta is the angle between the origin of the X,Y plane and ro and ranges from 0 to 2 pi
n1 is a positive number, but for clear representation is usually between 0.1 and 4. It determines the gross shape of the torus. The value used is chosen by the user.
n2 is described similarly to n1 but is not necessarily the same value as n1. It determines the shape of the cross section of the torus.
The value used is chosen by the user.
r1 is the radius of the cross section
phi is the angle between the X,Z plane and r1 and ranges from 0 to 2 pi.

With reference to the diagram:
torus1.jpg

consider the case where ro lies along the positive X axis (theta = 0). The circle for the cross section is on X,Z plane. The X coordinate for the centre of the representation of the cross section is (ro + r1). [Its full (X,Y,Z) coordinate would be ((ro + r1),0,0)

Having waded through all of this, and to make the question relevant to 3D design, I suppose I should pose the question:
How do I write this general formula is a way that it will work in OpenScad?

In other words, how do I get OpenScad to automatically use all the values for theta and phi in their respective ranges (0 to 2 pi)?

Old Man Emu