discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

circular array of arbitrary shapes

J
jon
Sun, Oct 23, 2022 1:17 PM

I want to create a ring of equally spaced objects.  In the code below,
those objects are circles, but I would like to be able to have triangles
or squares without having to clone the code 3 times.  Is there a way to
pass in the shape?

module LEDPattern(n, di) {
    // circular array  of "n" LEDs with diameter "di"
    an = 360/n;
    r = di/2 / sin(an/2);
    for (a = [0:an:359])
        rotate([0, 0, a])
            translate([r, 0, 0])
                // reduce circle sizes to keep disks from touching
                circle(d = 0.95 * di);
    }

I want to create a ring of equally spaced objects.  In the code below, those objects are circles, but I would like to be able to have triangles or squares without having to clone the code 3 times.  Is there a way to pass in the shape? module LEDPattern(n, di) {     // circular array  of "n" LEDs with diameter "di"     an = 360/n;     r = di/2 / sin(an/2);     for (a = [0:an:359])         rotate([0, 0, a])             translate([r, 0, 0])                 // reduce circle sizes to keep disks from touching                 circle(d = 0.95 * di);     }
SP
Sanjeev Prabhakar
Sun, Oct 23, 2022 1:24 PM

Most of the time I get it wrong.

If you can share a sketch of what you want, maybe I can help in this case
(just to make sure my understanding is correct).

There is a function quaternion rotation which I normally use to rotate
various objects

On Sun, 23 Oct, 2022, 6:47 pm jon, jon@jonbondy.com wrote:

I want to create a ring of equally spaced objects.  In the code below,
those objects are circles, but I would like to be able to have triangles
or squares without having to clone the code 3 times.  Is there a way to
pass in the shape?

module LEDPattern(n, di) {
// circular array  of "n" LEDs with diameter "di"
an = 360/n;
r = di/2 / sin(an/2);
for (a = [0:an:359])
rotate([0, 0, a])
translate([r, 0, 0])
// reduce circle sizes to keep disks from touching
circle(d = 0.95 * di);
}


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

Most of the time I get it wrong. If you can share a sketch of what you want, maybe I can help in this case (just to make sure my understanding is correct). There is a function quaternion rotation which I normally use to rotate various objects On Sun, 23 Oct, 2022, 6:47 pm jon, <jon@jonbondy.com> wrote: > I want to create a ring of equally spaced objects. In the code below, > those objects are circles, but I would like to be able to have triangles > or squares without having to clone the code 3 times. Is there a way to > pass in the shape? > > module LEDPattern(n, di) { > // circular array of "n" LEDs with diameter "di" > an = 360/n; > r = di/2 / sin(an/2); > for (a = [0:an:359]) > rotate([0, 0, a]) > translate([r, 0, 0]) > // reduce circle sizes to keep disks from touching > circle(d = 0.95 * di); > } > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
J
jon
Sun, Oct 23, 2022 1:41 PM

I want to replace "circle(d = 0.95 * di);" on the bottom with, say,
"square(0.95 * di)" without cloning the code.  My question has nothing
to deal with rotation, that I am aware.  I want to pass the shape
(circle or square) in as a parameter to the module.

On 10/23/2022 9:24 AM, Sanjeev Prabhakar wrote:

Most of the time I get it wrong.

If you can share a sketch of what you want, maybe I can help in this
case (just to make sure my understanding is correct).

There is a function quaternion rotation which I normally use to rotate
various objects

On Sun, 23 Oct, 2022, 6:47 pm jon, jon@jonbondy.com wrote:

 I want to create a ring of equally spaced objects.  In the code
 below,
 those objects are circles, but I would like to be able to have
 triangles
 or squares without having to clone the code 3 times.  Is there a
 way to
 pass in the shape?

 module LEDPattern(n, di) {
      // circular array  of "n" LEDs with diameter "di"
      an = 360/n;
      r = di/2 / sin(an/2);
      for (a = [0:an:359])
          rotate([0, 0, a])
              translate([r, 0, 0])
                  // reduce circle sizes to keep disks from touching
                  circle(d = 0.95 * di);
      }
 _______________________________________________
 OpenSCAD mailing list
 To unsubscribe send an email to discuss-leave@lists.openscad.org

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

I want to replace "circle(d = 0.95 * di);" on the bottom with, say, "square(0.95 * di)" without cloning the code.  My question has nothing to deal with rotation, that I am aware.  I want to pass the shape (circle or square) in as a parameter to the module. On 10/23/2022 9:24 AM, Sanjeev Prabhakar wrote: > Most of the time I get it wrong. > > If you can share a sketch of what you want, maybe I can help in this > case (just to make sure my understanding is correct). > > There is a function quaternion rotation which I normally use to rotate > various objects > > > On Sun, 23 Oct, 2022, 6:47 pm jon, <jon@jonbondy.com> wrote: > > I want to create a ring of equally spaced objects.  In the code > below, > those objects are circles, but I would like to be able to have > triangles > or squares without having to clone the code 3 times.  Is there a > way to > pass in the shape? > > module LEDPattern(n, di) { >      // circular array  of "n" LEDs with diameter "di" >      an = 360/n; >      r = di/2 / sin(an/2); >      for (a = [0:an:359]) >          rotate([0, 0, a]) >              translate([r, 0, 0]) >                  // reduce circle sizes to keep disks from touching >                  circle(d = 0.95 * di); >      } > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org > > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email todiscuss-leave@lists.openscad.org
RP
Ronaldo Persiano
Sun, Oct 23, 2022 1:50 PM

See the children() mechanism in the OpenSCAD manual
https://en.m.wikibooks.org/wiki/OpenSCAD_User_Manual/User-Defined_Functions_and_Modules

in the section module.

Em dom., 23 de out. de 2022 10:41, jon jon@jonbondy.com escreveu:

I want to replace "circle(d = 0.95 * di);" on the bottom with, say,
"square(0.95 * di)" without cloning the code.  My question has nothing to
deal with rotation, that I am aware.  I want to pass the shape (circle or
square) in as a parameter to the module.

On 10/23/2022 9:24 AM, Sanjeev Prabhakar wrote:

Most of the time I get it wrong.

If you can share a sketch of what you want, maybe I can help in this case
(just to make sure my understanding is correct).

There is a function quaternion rotation which I normally use to rotate
various objects

On Sun, 23 Oct, 2022, 6:47 pm jon, jon@jonbondy.com wrote:

I want to create a ring of equally spaced objects.  In the code below,
those objects are circles, but I would like to be able to have triangles
or squares without having to clone the code 3 times.  Is there a way to
pass in the shape?

module LEDPattern(n, di) {
// circular array  of "n" LEDs with diameter "di"
an = 360/n;
r = di/2 / sin(an/2);
for (a = [0:an:359])
rotate([0, 0, a])
translate([r, 0, 0])
// reduce circle sizes to keep disks from touching
circle(d = 0.95 * di);
}


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


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


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

See the children() mechanism in the OpenSCAD manual https://en.m.wikibooks.org/wiki/OpenSCAD_User_Manual/User-Defined_Functions_and_Modules in the section module. Em dom., 23 de out. de 2022 10:41, jon <jon@jonbondy.com> escreveu: > I want to replace "circle(d = 0.95 * di);" on the bottom with, say, > "square(0.95 * di)" without cloning the code. My question has nothing to > deal with rotation, that I am aware. I want to pass the shape (circle or > square) in as a parameter to the module. > > > On 10/23/2022 9:24 AM, Sanjeev Prabhakar wrote: > > Most of the time I get it wrong. > > If you can share a sketch of what you want, maybe I can help in this case > (just to make sure my understanding is correct). > > There is a function quaternion rotation which I normally use to rotate > various objects > > > On Sun, 23 Oct, 2022, 6:47 pm jon, <jon@jonbondy.com> wrote: > >> I want to create a ring of equally spaced objects. In the code below, >> those objects are circles, but I would like to be able to have triangles >> or squares without having to clone the code 3 times. Is there a way to >> pass in the shape? >> >> module LEDPattern(n, di) { >> // circular array of "n" LEDs with diameter "di" >> an = 360/n; >> r = di/2 / sin(an/2); >> for (a = [0:an:359]) >> rotate([0, 0, a]) >> translate([r, 0, 0]) >> // reduce circle sizes to keep disks from touching >> circle(d = 0.95 * di); >> } >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
SP
Sanjeev Prabhakar
Sun, Oct 23, 2022 1:55 PM

module LEDPattern(n, di) {
// circular array  of "n" LEDs with diameter "di"
an = 360/n;
r = di/2 / sin(an/2);
for (a = [0:an:359])
rotate([0, 0, a])
translate([r, 0, 0])
// reduce circle sizes to keep disks from touching
circle(di/2*.95,$fn=3);
}

LEDPattern(5,20);

see if this works ($fn can define various shapes)

On Sun, 23 Oct 2022 at 19:11, jon jon@jonbondy.com wrote:

I want to replace "circle(d = 0.95 * di);" on the bottom with, say,
"square(0.95 * di)" without cloning the code.  My question has nothing to
deal with rotation, that I am aware.  I want to pass the shape (circle or
square) in as a parameter to the module.

On 10/23/2022 9:24 AM, Sanjeev Prabhakar wrote:

Most of the time I get it wrong.

If you can share a sketch of what you want, maybe I can help in this case
(just to make sure my understanding is correct).

There is a function quaternion rotation which I normally use to rotate
various objects

On Sun, 23 Oct, 2022, 6:47 pm jon, jon@jonbondy.com wrote:

I want to create a ring of equally spaced objects.  In the code below,
those objects are circles, but I would like to be able to have triangles
or squares without having to clone the code 3 times.  Is there a way to
pass in the shape?

module LEDPattern(n, di) {
// circular array  of "n" LEDs with diameter "di"
an = 360/n;
r = di/2 / sin(an/2);
for (a = [0:an:359])
rotate([0, 0, a])
translate([r, 0, 0])
// reduce circle sizes to keep disks from touching
circle(d = 0.95 * di);
}


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


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

module LEDPattern(n, di) { // circular array of "n" LEDs with diameter "di" an = 360/n; r = di/2 / sin(an/2); for (a = [0:an:359]) rotate([0, 0, a]) translate([r, 0, 0]) // reduce circle sizes to keep disks from touching circle(di/2*.95,$fn=3); } LEDPattern(5,20); see if this works ($fn can define various shapes) On Sun, 23 Oct 2022 at 19:11, jon <jon@jonbondy.com> wrote: > I want to replace "circle(d = 0.95 * di);" on the bottom with, say, > "square(0.95 * di)" without cloning the code. My question has nothing to > deal with rotation, that I am aware. I want to pass the shape (circle or > square) in as a parameter to the module. > > > On 10/23/2022 9:24 AM, Sanjeev Prabhakar wrote: > > Most of the time I get it wrong. > > If you can share a sketch of what you want, maybe I can help in this case > (just to make sure my understanding is correct). > > There is a function quaternion rotation which I normally use to rotate > various objects > > > On Sun, 23 Oct, 2022, 6:47 pm jon, <jon@jonbondy.com> wrote: > >> I want to create a ring of equally spaced objects. In the code below, >> those objects are circles, but I would like to be able to have triangles >> or squares without having to clone the code 3 times. Is there a way to >> pass in the shape? >> >> module LEDPattern(n, di) { >> // circular array of "n" LEDs with diameter "di" >> an = 360/n; >> r = di/2 / sin(an/2); >> for (a = [0:an:359]) >> rotate([0, 0, a]) >> translate([r, 0, 0]) >> // reduce circle sizes to keep disks from touching >> circle(d = 0.95 * di); >> } >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org > >
L
larry
Sun, Oct 23, 2022 2:24 PM

On Sun, 2022-10-23 at 09:17 -0400, jon wrote:

I want to create a ring of equally spaced objects.  In the code
below,
those objects are circles, but I would like to be able to have
triangles
or squares without having to clone the code 3 times.  Is there a way
to
pass in the shape?

LEDPattern(36, 4, 4);

module LEDPattern(n, di, s) {
// circular array  of "n" LEDs with diameter "di", and s = sides
an = 360/n;
r = di/2 / sin(an/2);
for (a = [0:an:359])
rotate([0, 0, a])
translate([r, 0, 0])
// reduce circle sizes to keep disks from touching
circle(d = 0.95 * di, $fn=s);
}

module LEDPattern(n, di) {
     // circular array  of "n" LEDs with diameter "di"
     an = 360/n;
     r = di/2 / sin(an/2);
     for (a = [0:an:359])
         rotate([0, 0, a])
             translate([r, 0, 0])
                 // reduce circle sizes to keep disks from touching
                 circle(d = 0.95 * di);
     }


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

On Sun, 2022-10-23 at 09:17 -0400, jon wrote: > I want to create a ring of equally spaced objects.  In the code > below, > those objects are circles, but I would like to be able to have > triangles > or squares without having to clone the code 3 times.  Is there a way > to > pass in the shape? LEDPattern(36, 4, 4); module LEDPattern(n, di, s) { // circular array of "n" LEDs with diameter "di", and s = sides an = 360/n; r = di/2 / sin(an/2); for (a = [0:an:359]) rotate([0, 0, a]) translate([r, 0, 0]) // reduce circle sizes to keep disks from touching circle(d = 0.95 * di, $fn=s); } > module LEDPattern(n, di) { >      // circular array  of "n" LEDs with diameter "di" >      an = 360/n; >      r = di/2 / sin(an/2); >      for (a = [0:an:359]) >          rotate([0, 0, a]) >              translate([r, 0, 0]) >                  // reduce circle sizes to keep disks from touching >                  circle(d = 0.95 * di); >      } > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
J
jon
Sun, Oct 23, 2022 2:38 PM

Thanks to everyone.  The shapes I want are not just changes in $fn: they
are more complex, although my example was simpler.  I tried to use
function literals for this, and gave up.  For the time being, I will
enable/disable the variations using the "*". Stupid and clunky, but the
job is done, and I can move on.

Jon

On 10/23/2022 10:24 AM, larry wrote:

On Sun, 2022-10-23 at 09:17 -0400, jon wrote:

I want to create a ring of equally spaced objects.  In the code
below,
those objects are circles, but I would like to be able to have
triangles
or squares without having to clone the code 3 times.  Is there a way
to
pass in the shape?
LEDPattern(36, 4, 4);

module LEDPattern(n, di, s) {
// circular array  of "n" LEDs with diameter "di", and s = sides
an = 360/n;
r = di/2 / sin(an/2);
for (a = [0:an:359])
rotate([0, 0, a])
translate([r, 0, 0])
// reduce circle sizes to keep disks from touching
circle(d = 0.95 * di, $fn=s);
}

module LEDPattern(n, di) {
     // circular array  of "n" LEDs with diameter "di"
     an = 360/n;
     r = di/2 / sin(an/2);
     for (a = [0:an:359])
         rotate([0, 0, a])
             translate([r, 0, 0])
                 // reduce circle sizes to keep disks from touching
                 circle(d = 0.95 * di);
     }


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


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

Thanks to everyone.  The shapes I want are not just changes in $fn: they are more complex, although my example was simpler.  I tried to use function literals for this, and gave up.  For the time being, I will enable/disable the variations using the "*". Stupid and clunky, but the job is done, and I can move on. Jon On 10/23/2022 10:24 AM, larry wrote: > On Sun, 2022-10-23 at 09:17 -0400, jon wrote: >> I want to create a ring of equally spaced objects.  In the code >> below, >> those objects are circles, but I would like to be able to have >> triangles >> or squares without having to clone the code 3 times.  Is there a way >> to >> pass in the shape? > LEDPattern(36, 4, 4); > > module LEDPattern(n, di, s) { > // circular array of "n" LEDs with diameter "di", and s = sides > an = 360/n; > r = di/2 / sin(an/2); > for (a = [0:an:359]) > rotate([0, 0, a]) > translate([r, 0, 0]) > // reduce circle sizes to keep disks from touching > circle(d = 0.95 * di, $fn=s); > } > >> module LEDPattern(n, di) { >>      // circular array  of "n" LEDs with diameter "di" >>      an = 360/n; >>      r = di/2 / sin(an/2); >>      for (a = [0:an:359]) >>          rotate([0, 0, a]) >>              translate([r, 0, 0]) >>                  // reduce circle sizes to keep disks from touching >>                  circle(d = 0.95 * di); >>      } >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
AM
Adrian Mariano
Sun, Oct 23, 2022 2:39 PM

As Ronaldo says, use the children mechanism.  Replace circle() with
children() in your code and invoke by LEDPattern(...) square(...) or
whatever you want.  Note that BOSL2 has a rot_copies() module to do this
task.

On Sun, Oct 23, 2022 at 9:17 AM jon jon@jonbondy.com wrote:

I want to create a ring of equally spaced objects.  In the code below,
those objects are circles, but I would like to be able to have triangles
or squares without having to clone the code 3 times.  Is there a way to
pass in the shape?

module LEDPattern(n, di) {
// circular array  of "n" LEDs with diameter "di"
an = 360/n;
r = di/2 / sin(an/2);
for (a = [0:an:359])
rotate([0, 0, a])
translate([r, 0, 0])
// reduce circle sizes to keep disks from touching
circle(d = 0.95 * di);
}


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

As Ronaldo says, use the children mechanism. Replace circle() with children() in your code and invoke by LEDPattern(...) square(...) or whatever you want. Note that BOSL2 has a rot_copies() module to do this task. On Sun, Oct 23, 2022 at 9:17 AM jon <jon@jonbondy.com> wrote: > I want to create a ring of equally spaced objects. In the code below, > those objects are circles, but I would like to be able to have triangles > or squares without having to clone the code 3 times. Is there a way to > pass in the shape? > > module LEDPattern(n, di) { > // circular array of "n" LEDs with diameter "di" > an = 360/n; > r = di/2 / sin(an/2); > for (a = [0:an:359]) > rotate([0, 0, a]) > translate([r, 0, 0]) > // reduce circle sizes to keep disks from touching > circle(d = 0.95 * di); > } > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
RW
Raymond West
Sun, Oct 23, 2022 2:52 PM

Clone the code. Triangles and squares have orientation. which will need
at least another rotation, depending on which way you want them to
point. As Sanjeev said, $fn will generate triangles, or squares, but you
may need to adjust the size of the circle, and also the orientation too.
But if you just want to poke the led into a round hole, then no need to
worry about the rotate, (but if you measure the af of the square, it
won't fit in the hole, you need the diagonal. I'll leave the triangle
measurement to someone else.

On 23/10/2022 14:41, jon wrote:

I want to replace "circle(d = 0.95 * di);" on the bottom with, say,
"square(0.95 * di)" without cloning the code.  My question has nothing
to deal with rotation, that I am aware.  I want to pass the shape
(circle or square) in as a parameter to the module.

On 10/23/2022 9:24 AM, Sanjeev Prabhakar wrote:

Most of the time I get it wrong.

If you can share a sketch of what you want, maybe I can help in this
case (just to make sure my understanding is correct).

There is a function quaternion rotation which I normally use to
rotate various objects

On Sun, 23 Oct, 2022, 6:47 pm jon, jon@jonbondy.com wrote:

 I want to create a ring of equally spaced objects.  In the code
 below,
 those objects are circles, but I would like to be able to have
 triangles
 or squares without having to clone the code 3 times.  Is there a
 way to
 pass in the shape?

 module LEDPattern(n, di) {
      // circular array  of "n" LEDs with diameter "di"
      an = 360/n;
      r = di/2 / sin(an/2);
      for (a = [0:an:359])
          rotate([0, 0, a])
              translate([r, 0, 0])
                  // reduce circle sizes to keep disks from touching
                  circle(d = 0.95 * di);
      }
 _______________________________________________
 OpenSCAD mailing list
 To unsubscribe send an email to discuss-leave@lists.openscad.org

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


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

Clone the code. Triangles and squares have orientation. which will need at least another rotation, depending on which way you want them to point. As Sanjeev said, $fn will generate triangles, or squares, but you may need to adjust the size of the circle, and also the orientation too. But if you just want to poke the led into a round hole, then no need to worry about the rotate, (but if you measure the af of the square, it won't fit in the hole, you need the diagonal. I'll leave the triangle measurement to someone else. On 23/10/2022 14:41, jon wrote: > > I want to replace "circle(d = 0.95 * di);" on the bottom with, say, > "square(0.95 * di)" without cloning the code.  My question has nothing > to deal with rotation, that I am aware.  I want to pass the shape > (circle or square) in as a parameter to the module. > > > On 10/23/2022 9:24 AM, Sanjeev Prabhakar wrote: >> Most of the time I get it wrong. >> >> If you can share a sketch of what you want, maybe I can help in this >> case (just to make sure my understanding is correct). >> >> There is a function quaternion rotation which I normally use to >> rotate various objects >> >> >> On Sun, 23 Oct, 2022, 6:47 pm jon, <jon@jonbondy.com> wrote: >> >> I want to create a ring of equally spaced objects.  In the code >> below, >> those objects are circles, but I would like to be able to have >> triangles >> or squares without having to clone the code 3 times.  Is there a >> way to >> pass in the shape? >> >> module LEDPattern(n, di) { >>      // circular array  of "n" LEDs with diameter "di" >>      an = 360/n; >>      r = di/2 / sin(an/2); >>      for (a = [0:an:359]) >>          rotate([0, 0, a]) >>              translate([r, 0, 0]) >>                  // reduce circle sizes to keep disks from touching >>                  circle(d = 0.95 * di); >>      } >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> >> >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email todiscuss-leave@lists.openscad.org > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email todiscuss-leave@lists.openscad.org
AM
Adrian Mariano
Sun, Oct 23, 2022 3:08 PM

Ug, no do not clone the code.  Triangles and squares have orientation, yes,
and you can correctly adjust with a single block of code if you don't want
the natural thing, which would be the object simply rotated into position.

The way that rot_copies() works in BOSL2 is that it sets $ang and $idx
which give the angle of the item and the index number of the item
respectively, so you can adjust size, angle, color, or anything you want.
Want to make objects alternate between square and circle, just check if
$idx is even.

include<BOSL2/std.scad>
zrot_copies(n=8, d=10)
if ($idx % 2) square(1,center=true);
else circle(d=1,$fn=12);

gives this:

[image: image.png]

or

include<BOSL2/std.scad>
zrot_copies(n=8, d=10)
circle(d=1+$idx/5, $fn=12);

[image: image.png]

Triangles all pointing down:

zrot_copies(n=8, d=10, subrot=false)
rot(30)circle(d=2, $fn=3);

[image: image.png]

On Sun, Oct 23, 2022 at 10:53 AM Raymond West raywest@raywest.com wrote:

Clone the code. Triangles and squares have orientation. which will need at
least another rotation, depending on which way you want them to point. As
Sanjeev said, $fn will generate triangles, or squares, but you may need to
adjust the size of the circle, and also the orientation too. But if you
just want to poke the led into a round hole, then no need to worry about
the rotate, (but if you measure the af of the square, it won't fit in the
hole, you need the diagonal. I'll leave the triangle measurement to someone
else.
On 23/10/2022 14:41, jon wrote:

I want to replace "circle(d = 0.95 * di);" on the bottom with, say,
"square(0.95 * di)" without cloning the code.  My question has nothing to
deal with rotation, that I am aware.  I want to pass the shape (circle or
square) in as a parameter to the module.

On 10/23/2022 9:24 AM, Sanjeev Prabhakar wrote:

Most of the time I get it wrong.

If you can share a sketch of what you want, maybe I can help in this case
(just to make sure my understanding is correct).

There is a function quaternion rotation which I normally use to rotate
various objects

On Sun, 23 Oct, 2022, 6:47 pm jon, jon@jonbondy.com wrote:

I want to create a ring of equally spaced objects.  In the code below,
those objects are circles, but I would like to be able to have triangles
or squares without having to clone the code 3 times.  Is there a way to
pass in the shape?

module LEDPattern(n, di) {
// circular array  of "n" LEDs with diameter "di"
an = 360/n;
r = di/2 / sin(an/2);
for (a = [0:an:359])
rotate([0, 0, a])
translate([r, 0, 0])
// reduce circle sizes to keep disks from touching
circle(d = 0.95 * di);
}


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


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


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


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

Ug, no do not clone the code. Triangles and squares have orientation, yes, and you can correctly adjust with a single block of code if you don't want the natural thing, which would be the object simply rotated into position. The way that rot_copies() works in BOSL2 is that it sets $ang and $idx which give the angle of the item and the index number of the item respectively, so you can adjust size, angle, color, or anything you want. Want to make objects alternate between square and circle, just check if $idx is even. include<BOSL2/std.scad> zrot_copies(n=8, d=10) if ($idx % 2) square(1,center=true); else circle(d=1,$fn=12); gives this: [image: image.png] or include<BOSL2/std.scad> zrot_copies(n=8, d=10) circle(d=1+$idx/5, $fn=12); [image: image.png] Triangles all pointing down: zrot_copies(n=8, d=10, subrot=false) rot(30)circle(d=2, $fn=3); [image: image.png] On Sun, Oct 23, 2022 at 10:53 AM Raymond West <raywest@raywest.com> wrote: > Clone the code. Triangles and squares have orientation. which will need at > least another rotation, depending on which way you want them to point. As > Sanjeev said, $fn will generate triangles, or squares, but you may need to > adjust the size of the circle, and also the orientation too. But if you > just want to poke the led into a round hole, then no need to worry about > the rotate, (but if you measure the af of the square, it won't fit in the > hole, you need the diagonal. I'll leave the triangle measurement to someone > else. > On 23/10/2022 14:41, jon wrote: > > I want to replace "circle(d = 0.95 * di);" on the bottom with, say, > "square(0.95 * di)" without cloning the code. My question has nothing to > deal with rotation, that I am aware. I want to pass the shape (circle or > square) in as a parameter to the module. > > > On 10/23/2022 9:24 AM, Sanjeev Prabhakar wrote: > > Most of the time I get it wrong. > > If you can share a sketch of what you want, maybe I can help in this case > (just to make sure my understanding is correct). > > There is a function quaternion rotation which I normally use to rotate > various objects > > > On Sun, 23 Oct, 2022, 6:47 pm jon, <jon@jonbondy.com> wrote: > >> I want to create a ring of equally spaced objects. In the code below, >> those objects are circles, but I would like to be able to have triangles >> or squares without having to clone the code 3 times. Is there a way to >> pass in the shape? >> >> module LEDPattern(n, di) { >> // circular array of "n" LEDs with diameter "di" >> an = 360/n; >> r = di/2 / sin(an/2); >> for (a = [0:an:359]) >> rotate([0, 0, a]) >> translate([r, 0, 0]) >> // reduce circle sizes to keep disks from touching >> circle(d = 0.95 * di); >> } >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org >> > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org > > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >