[OpenSCAD] Twisted Torus

Ezra Reynolds shadowwynd at gmail.com
Tue Sep 25 20:24:05 EDT 2018


The quick answer is that you are mixing 2D (square, circle) and 3D. 
OpenScad treats 2D shapes as having a slight thickness for rendering 
purposes, but when creating an actual model the model will be blank 
because a square or circle does not exist in 3D space.

Adding a linear_extrude (1) (or some other thickness) will give the 
torus-slice a thickness, which is then (SLOWLY) added together to make a 
shape.  I say "SLOWLY" because it is going to be resource-intensive; 
OpenScad is slow on boolean operations, and it always performs a 
top-level union; so you have at least 360 boolean operations it has to 
calculate.

This could be sped up by having fewer, but thicker, slices.  The true 
wizards here can come up with some variant that uses list comprehension 
to generate a polyhedron that will render in blazing speed, but that is 
outside my skill.

Side note, the matching brace style is known as Allman style or BSD 
style.  I prefer this style myself, although brace style is one of the 
Great Religious Flame War topics among programmers.

-------------------------------

Here is your code, with a slice size of 10 (affects both the loop and 
the linear_extrude).  Renders in decent time on my machine.  The finer 
resolution you go the slower it will be.

------------------------



twistedTorus( 25, 50 );

module twistedTorus( r1, r2, t )
{
     for( i = [0:10:360] )
     {
         rotate( [90, 0, i] )
         {
             translate( [r2, 0, 0] )
             {
                 rotate( [0, 0, i] )
                 {
                     linear_extrude(10) difference()
                     {
                         circle( r1 );
                         translate( [0, -r1, 0] ) square( [r1, 2*r1] );
                     }
                 }
             }
         }
     }
}


------------------------------
On 2018-09-25 7:35 PM, Zacariaz wrote:
> twistedTorus( 25, 50 );
> #translate( [50, 0, 0] ) rotate( [90, 180, 0] ) twistedTorus( 25, 50 );
>
> module twistedTorus( r1, r2, t )
> {
>      for( i = [0:1:360] )
>      {
>          rotate( [90, 0, i] )
>          {
>              translate( [r2, 0, 0] )
>              {
>                  rotate( [0, 0, i] )
>                  {
>                      difference()
>                      {
>                          circle( r1 );
>                          translate( [0, -r1, 0] ) square( [r1, 2*r1] );
>                      }
>                  }
>              }
>          }
>      }
> }
>
> Also I apologize for all the curly bracket, but I like to keep things in
> order, inconvenient though it may be.;)
> The issue should be evident. The model is only a facsimile, and a bad one at
> that. It is very resource intensive to render even in it's current form and
> if you want to step it up a notch to something useful, you've got to find a
> better way, which is why I'm asking here, how to attach this problem.
>
> You could say that what I need is rotate_extrude_with_a_twist(), but I don't
> see how.



More information about the Discuss mailing list