discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

When does 'for' create an Implicit union?

SL
Steve Lelievre
Thu, Mar 6, 2025 5:21 PM

My code snippet

difference() {
  a = 10;
  for(i=[0,120,240]) linear_extrude(60) rotate(i) polygon(100 * [[0,0],
[cos(a), sin(a)], [cos(a), -sin(a)]]);
  cylinder(r=42, h = 60);
}

does not do what I want, but adding a union() before the for() command
fixes it:

difference() {
  a = 10;
  union() for(i=[0,120,240]) linear_extrude(60) rotate(i) polygon(100 *
[[0,0], [cos(a), sin(a)], [cos(a), -sin(a)]]);
  cylinder(r=42, h = 60);
}

As part of the explanation of intersection_for(), the wiki documentation
states "Besides creating separate instances for each pass, the standard
for() also groups all these instances creating an implicit union" but
that clearly isn't so for my example. Is there a way I can predict when
it will happen?

Cheers,

Steve

My code snippet difference() {   a = 10;   for(i=[0,120,240]) linear_extrude(60) rotate(i) polygon(100 * [[0,0], [cos(a), sin(a)], [cos(a), -sin(a)]]);   cylinder(r=42, h = 60); } does not do what I want, but adding a union() before the for() command fixes it: difference() {   a = 10;   union() for(i=[0,120,240]) linear_extrude(60) rotate(i) polygon(100 * [[0,0], [cos(a), sin(a)], [cos(a), -sin(a)]]);   cylinder(r=42, h = 60); } As part of the explanation of intersection_for(), the wiki documentation states "Besides creating separate instances for each pass, the standard *for()* also groups all these instances creating an implicit union" but that clearly isn't so for my example. Is there a way I can predict when it will happen? Cheers, Steve
JB
Jordan Brown
Thu, Mar 6, 2025 5:30 PM

for() normally creates an implicit union.  (As does almost everything.)

Perhaps you have "lazy union" enabled.  Don't do that.  Edit /
Preferences / Features.

  union() for(i=[0,120,240]) linear_extrude(60) rotate(i) polygon(100

  • [[0,0], [cos(a), sin(a)], [cos(a), -sin(a)]]);
      cylinder(r=42, h = 60);

Hint:

You might notice preview artifacts at the top and bottom.

These are because the previewer can't decide whether there's anything
left after the difference.  Make the negative object extend at least a
little past the thing you're subtracting it from.  In this case, an easy
scheme is to multiply the height of the negative object by three, and
center it.  That will ensure that it projects on both sides of the
positive object, no matter whether it's aligned with one side, the
other, or the center.

  cylinder(r=42, h = 60*3, center=true);
for() normally creates an implicit union.  (As does almost everything.) Perhaps you have "lazy union" enabled.  Don't do that.  Edit / Preferences / Features. >   union() for(i=[0,120,240]) linear_extrude(60) rotate(i) polygon(100 > * [[0,0], [cos(a), sin(a)], [cos(a), -sin(a)]]); >   cylinder(r=42, h = 60); > Hint: You might notice preview artifacts at the top and bottom. These are because the previewer can't decide whether there's anything left after the difference.  Make the negative object extend at least a little past the thing you're subtracting it from.  In this case, an easy scheme is to multiply the height of the negative object by three, and center it.  That will ensure that it projects on both sides of the positive object, no matter whether it's aligned with one side, the other, or the center. cylinder(r=42, h = 60*3, center=true);
SL
Steve Lelievre
Thu, Mar 6, 2025 5:33 PM

On 2025-03-06 9:30 a.m., Jordan Brown wrote:

for() normally creates an implicit union.  (As does almost everything.)

Perhaps you have "lazy union" enabled.  Don't do that.  Edit /
Preferences / Features.

That fixed it. Thank you.

Steve

On 2025-03-06 9:30 a.m., Jordan Brown wrote: > for() normally creates an implicit union.  (As does almost everything.) > > Perhaps you have "lazy union" enabled.  Don't do that.  Edit / > Preferences / Features. That fixed it. Thank you. Steve
JD
John David
Fri, Mar 7, 2025 3:50 AM

What version are you running?  I'm currently on v2021.01, and I cannot find
any "features" tab in the preferences pop-up.

Also, is there some way to remove those pesky miniscule thin flotsam from
the difference operations?

EBo --

On Thu, Mar 6, 2025 at 12:33 PM Steve Lelievre via Discuss <
discuss@lists.openscad.org> wrote:

On 2025-03-06 9:30 a.m., Jordan Brown wrote:

for() normally creates an implicit union.  (As does almost everything.)

Perhaps you have "lazy union" enabled.  Don't do that.  Edit /
Preferences / Features.

That fixed it. Thank you.

Steve


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

What version are you running? I'm currently on v2021.01, and I cannot find any "features" tab in the preferences pop-up. Also, is there some way to remove those pesky miniscule thin flotsam from the difference operations? EBo -- On Thu, Mar 6, 2025 at 12:33 PM Steve Lelievre via Discuss < discuss@lists.openscad.org> wrote: > > On 2025-03-06 9:30 a.m., Jordan Brown wrote: > > for() normally creates an implicit union. (As does almost everything.) > > > > Perhaps you have "lazy union" enabled. Don't do that. Edit / > > Preferences / Features. > > > That fixed it. Thank you. > > Steve > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
SL
Steve Lelievre
Fri, Mar 7, 2025 3:55 AM

On 2025-03-06 7:50 p.m., John David wrote:

What version are you running?  I'm currently on v2021.01, and I cannot
find any "features" tab in the preferences pop-up.

It's in the development builds.

Also, is there some way to remove those pesky miniscule thin flotsam
from the difference operations?

As Jordan mentioned, you can make the item being differenced away
slightly too big so that it breaks through the surface.

I usually render rather than  preview, so I usually don't see those
artifacts anyway.

Steve

  EBo --

On Thu, Mar 6, 2025 at 12:33 PM Steve Lelievre via Discuss
discuss@lists.openscad.org wrote:

 On 2025-03-06 9:30 a.m., Jordan Brown wrote:

for() normally creates an implicit union.  (As does almost

 everything.)

Perhaps you have "lazy union" enabled.  Don't do that. Edit /
Preferences / Features.

 That fixed it. Thank you.

 Steve
 _______________________________________________
 OpenSCAD mailing list
 To unsubscribe send an email to discuss-leave@lists.openscad.org
On 2025-03-06 7:50 p.m., John David wrote: > What version are you running?  I'm currently on v2021.01, and I cannot > find any "features" tab in the preferences pop-up. It's in the development builds. > Also, is there some way to remove those pesky miniscule thin flotsam > from the difference operations? As Jordan mentioned, you can make the item being differenced away slightly too big so that it breaks through the surface. I usually render rather than  preview, so I usually don't see those artifacts anyway. Steve > >   EBo -- > > On Thu, Mar 6, 2025 at 12:33 PM Steve Lelievre via Discuss > <discuss@lists.openscad.org> wrote: > > > On 2025-03-06 9:30 a.m., Jordan Brown wrote: > > for() normally creates an implicit union.  (As does almost > everything.) > > > > Perhaps you have "lazy union" enabled.  Don't do that. Edit / > > Preferences / Features. > > > That fixed it. Thank you. > > Steve > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org > -- https://www.gnomoni.ca https://www.youtube.com/@gnomonica
JB
Jordan Brown
Fri, Mar 7, 2025 5:50 AM

On 3/6/2025 7:50 PM, John David wrote:

What version are you running?  I'm currently on v2021.01, and I cannot
find any "features" tab in the preferences pop-up.

I don't think there are any experimental features built into 2021.01.

Also, is there some way to remove those pesky miniscule thin flotsam
from the difference operations?

I see that Steve has already explained, but here's the FAQ reference:

https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/FAQ#What_are_those_strange_flickering_artifacts_in_the_preview?

Several of the other FAQs in that section are common display issues;
it's worth glancing through them.

On 3/6/2025 7:50 PM, John David wrote: > What version are you running?  I'm currently on v2021.01, and I cannot > find any "features" tab in the preferences pop-up. I don't think there are any experimental features built into 2021.01. > Also, is there some way to remove those pesky miniscule thin flotsam > from the difference operations? I see that Steve has already explained, but here's the FAQ reference: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/FAQ#What_are_those_strange_flickering_artifacts_in_the_preview? Several of the other FAQs in that section are common display issues; it's worth glancing through them.