discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: It's logical?

MM
Michael Möller
Thu, Dec 29, 2022 12:03 AM

I'd just let the for loops produce the whole grid and put the "if" in the
innermost place. It would then say
if ( (col_counter % 4 != 0) && (row_counter % 4 != 0 ) )

Msquare

On Thu, 29 Dec 2022 at 00:52, fred via Discuss discuss@lists.openscad.org
wrote:

---------- Forwarded message ----------
From: fred fred_dot_u@yahoo.com
To: OpenSCAD general discussion discuss@lists.openscad.org
Cc:
Bcc:
Date: Wed, 28 Dec 2022 23:51:58 +0000 (UTC)
Subject: [OpenSCAD] It's logical?
I'm able to generate an array of objects, 9 x 9 translating the desired
distances, by using a pair of nested for loops. Conveniently centered, the
81 items appear as expected.

thick = 5;
pin = 1;
base = 5;

x_spacing = 15;
y_spacing = 20;

module pocket(){
cylinder(h = thick, r1 = pin, r2 = base);
}

module pockets(){
for (col_counter = [-4 : 1 : 4])
//if (col_counter % 4 != 0)
for (row_counter = [-4 : 1 : 4])
translate([col_counter * x_spacing, row_counter * y_spacing,
0])
pocket();
}
pockets();

[image: Inline image]

The commented line does not behave as I'd like, but it does behave as
expected, removing the center column and the outer columns. It's an easy
matter to reposition the conditional and vanish the rows instead of the
columns, but my objective is different.

[image: Inline image]

[image: Inline image]

[image: Inline image]

I'd like to combine the if (col_counter % 4 != 0) and the if (row_counter
% 4 != 0) in such a way as to remove only the center pocket() and the
corner pocket()s and the edge-centered pocket()s.

I'm not sure of the logic necessary to get only those nine locations
ignored/skipped over/bypassed.

[image: Inline image]
This image above was created with a graphics editor and represents the
objective.
These pocket()s will be subtracted from a larger monolith and the "blank"
spots will have other shapes subtracted, in a less challenging approach, I
hope.

Is there an if-statement using boolean operators that will exclude the
mod_4 locations that can be nested in the loops?

---------- Forwarded message ----------
From: fred via Discuss discuss@lists.openscad.org
To: OpenSCAD general discussion discuss@lists.openscad.org
Cc: fred fred_dot_u@yahoo.com
Bcc:
Date: Wed, 28 Dec 2022 23:51:58 +0000 (UTC)
Subject: [OpenSCAD] It's logical?


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

I'd just let the for loops produce the whole grid and put the "if" in the innermost place. It would then say if ( (col_counter % 4 != 0) && (row_counter % 4 != 0 ) ) Msquare On Thu, 29 Dec 2022 at 00:52, fred via Discuss <discuss@lists.openscad.org> wrote: > > > > ---------- Forwarded message ---------- > From: fred <fred_dot_u@yahoo.com> > To: OpenSCAD general discussion <discuss@lists.openscad.org> > Cc: > Bcc: > Date: Wed, 28 Dec 2022 23:51:58 +0000 (UTC) > Subject: [OpenSCAD] It's logical? > I'm able to generate an array of objects, 9 x 9 translating the desired > distances, by using a pair of nested for loops. Conveniently centered, the > 81 items appear as expected. > > thick = 5; > pin = 1; > base = 5; > > x_spacing = 15; > y_spacing = 20; > > module pocket(){ > cylinder(h = thick, r1 = pin, r2 = base); > } > > module pockets(){ > for (col_counter = [-4 : 1 : 4]) > //if (col_counter % 4 != 0) > for (row_counter = [-4 : 1 : 4]) > translate([col_counter * x_spacing, row_counter * y_spacing, > 0]) > pocket(); > } > pockets(); > > [image: Inline image] > > > The commented line does not behave as I'd like, but it does behave as > expected, removing the center column and the outer columns. It's an easy > matter to reposition the conditional and vanish the rows instead of the > columns, but my objective is different. > > [image: Inline image] > > [image: Inline image] > > [image: Inline image] > > > > I'd like to combine the if (col_counter % 4 != 0) and the if (row_counter > % 4 != 0) in such a way as to remove only the center pocket() and the > corner pocket()s and the edge-centered pocket()s. > > I'm not sure of the logic necessary to get only those nine locations > ignored/skipped over/bypassed. > > [image: Inline image] > This image above was created with a graphics editor and represents the > objective. > These pocket()s will be subtracted from a larger monolith and the "blank" > spots will have other shapes subtracted, in a less challenging approach, I > hope. > > > Is there an if-statement using boolean operators that will exclude the > mod_4 locations that can be nested in the loops? > > > > > > ---------- Forwarded message ---------- > From: fred via Discuss <discuss@lists.openscad.org> > To: OpenSCAD general discussion <discuss@lists.openscad.org> > Cc: fred <fred_dot_u@yahoo.com> > Bcc: > Date: Wed, 28 Dec 2022 23:51:58 +0000 (UTC) > Subject: [OpenSCAD] It's logical? > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >