[OpenSCAD] Twisted Torus

Zacariaz zacariaz at gmail.com
Tue Oct 9 10:52:21 EDT 2018

Ronaldo wrote
> Nice done. Just 3 cents:
> a) there is a predefined variable PI in the language;
> b) it is usually advisable to avoid a float as increment of a for;
> c) the computation of the polyhedron vertices could be simply:
> p =
>     [
>     for( ta = [0:360/s2:359] )
>       for( i = [ta:360/seg:ca+ta] )
>             [
>                 -sin(ta)*(cos(i)*r1+r2),
>                 cos(ta)*(cos(i)*r1+r2),
>                 sin(i)*r1
>             ]
>     ];

As for your first point, good to know. Don't know how I've missed it, but in
this case it doesn't actually matter as it cancels out. It was more for
explanatory purposes.

Secondly I get what you're saying, and believe you me I've ha a lot of
trouble getting the for loops in openscad to behave. The first for loop
defining p pretty much explain the issue.
When working with integers, there really is not issue, because you can
always just say 
for( [begin:step:end-1] )
to get the actual range you're looking for, but if your step is not and
integer, in this case 360/s, you need to go to extremes ot make it work,
for( [0:360/s:360-360/s] )
which can course problems due to floating point "errors", and don't even get
me started on the case that the loop doesn't start at 0, in which case
you'll have to ensure that you start at a multiple of 360/s, which is pretty
much impossible, when working with floating point values.
I actually did plan to ask what to do in such situations, because it goes
without saying that sometimes 360 iterations just isn't enough to achieve
the desired resolution, so to speak.
Personally I'm used to the C syntax and would much rather have written
for( i = 0; round( i, 3 ) < 360; i += 360/s ) // 3 decimals should be ample
and I don't see how to achieve the same effect with openscad syntax, without
going to extremes.

Lastly, what about the center point? I know it isn't strictly needed when
splitting the torus in 2, but I do believe it increases the quality, and it
certainly is need if you wish to split it into 3 or more, or simply use some
arbitrary angle.
Or am I missing something?

And also thanks. To be honest, I can't help to be a little bit proud of
myself. Regardless, I do plan to try again from scratch, to see if I can't
do a better job of it.

Sent from: http://forum.openscad.org/

More information about the Discuss mailing list