[OpenSCAD] Why is this so heavy to OpenScad?

Hans L thehans at gmail.com
Sun Nov 10 15:58:47 EST 2019


MCAD's roundedBox is not particularly efficient.

Try this version (copied from example006.scad)

module rounded_cube(size,r,center=false)
{
  s = is_list(size) ? size : [size,size,size];
  translate(center ? -s/2 : [0,0,0])
    hull() {
      translate([    r,    r,    r]) sphere(r=r);
      translate([    r,    r,s.z-r]) sphere(r=r);
      translate([    r,s.y-r,    r]) sphere(r=r);
      translate([    r,s.y-r,s.z-r]) sphere(r=r);
      translate([s.x-r,    r,    r]) sphere(r=r);
      translate([s.x-r,    r,s.z-r]) sphere(r=r);
      translate([s.x-r,s.y-r,    r]) sphere(r=r);
      translate([s.x-r,s.y-r,s.z-r]) sphere(r=r);
    }
}

It doesn't have "sides only" version, but it should be easier to
compute, just replace the main loop body with your cage holes to call
that instead:

//roundedBox([cubW/3-dl,cubL/3-dl,cubH/3-dl],3, false);
rounded_cube([cubW/3-dl,cubL/3-dl,cubH/3-dl],3, true);


Also you can save a bit more computation if you ignore the center
column of "holes" like this:

if (!(sdx == 0 && sdy == 0)) translate([sdx*dx, sdy*dy, sdz*dz])

Hans

On Sun, Nov 10, 2019 at 2:45 PM Max Bond <max.o.bond at gmail.com> wrote:
>
> You can try using a higher value of $fa or using different values in different calls to roundedBox so you only use the high precision where you need it most.
>
> Your use case may vary.
>
> On Sun, Nov 10, 2019, 1:43 PM Max Bond <max.o.bond at gmail.com> wrote:
>>
>> I'd guess it's because you've set $fa to be 1.
>>
>> On Sun, Nov 10, 2019, 1:07 PM MVAckel via Discuss <discuss at lists.openscad.org> wrote:
>>>
>>> Hello,
>>>
>>> I'm trying to build a cage that will be later subtracted from a rounded box,
>>> but the cage is so heavy to  OpenScad (version 2019/05) that I'm not being
>>> able to do anything further.
>>>
>>> Is this a bug? Any other way of building the cage to be lighter?
>>>
>>> Marcos
>>>
>>>
>>>
>>> use <./MCAD/boxes.scad>;
>>>
>>> $fa=1;
>>> $fs=1;
>>>
>>>
>>> //----------------------
>>> cage();
>>> //----------------------
>>>
>>> cubW = 100;
>>> cubL = 100;
>>> cubH = 80;
>>> wall = 2.5;
>>> //--------------------------------------------------------------------------
>>>
>>> module cage()
>>> {
>>>
>>>         difference() {
>>>                 curv = 26;
>>>
>>>                 difference() {
>>>                         roundedBox( [cubH, cubL, cubW], curv, true );
>>>                         roundedBox( [cubH-2.0*wall,cubL-2.0*wall, cubW-2.0*wall], curv-2, true);
>>>                 }
>>>
>>>
>>>                 dl = -1.0;
>>>
>>>                 dx = cubW/3+2;
>>>                 dy = cubL/3+2;
>>>                 dz = cubH/3+2;
>>>                 for ( sdx = [ -1, 0, +1 ] ) {
>>>                         for ( sdy = [ -1, 0, +1] ) {
>>>                                 for ( sdz = [ -1, 0, +1] ) {
>>>                                         translate([sdx*dx, sdy*dy, sdz*dz])
>>> roundedBox([cubW/3-dl,cubL/3-dl,cubH/3-dl],3, false);
>>>                                 }
>>>                         }
>>>                 }
>>>         }
>>> }
>>> //--------------------------------------------------------------------------
>>> //--------------------------------------------------------------------------
>>>
>>>
>>>
>>>
>>>
>>> --
>>> Sent from: http://forum.openscad.org/
>>>
>>> _______________________________________________
>>> OpenSCAD mailing list
>>> Discuss at lists.openscad.org
>>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
> _______________________________________________
> OpenSCAD mailing list
> Discuss at lists.openscad.org
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org



More information about the Discuss mailing list