discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

referencing list elements

J
jon
Mon, Feb 27, 2023 9:23 PM

I tried to make a list of 3D locations (x, y, z) and then reference them
in a loop.  Clearly, I do not understand how to reference the elements
of a list.

sd = 0.5;    // sphere diameter
num = 10;    // number of x/y/z triplets
locs = [
    [1, 2, 3],
    [3, 4, 5],
    [5, 6, 7],
    [7, 8, 9],
    [1, 1, 1],
    [2, 2, 2],
    [3, 3, 3],
    [4, 4, 4],
    [5, 5, 5],
    [6, 6, 6]
    ];

for (i = [0:num-1])
    translate([locs[i, 0], locs[i, 1], locs[i, 2]])    // <===== error here
        sphere(d = sd);

I tried to make a list of 3D locations (x, y, z) and then reference them in a loop.  Clearly, I do not understand how to reference the elements of a list. sd = 0.5;    // sphere diameter num = 10;    // number of x/y/z triplets locs = [     [1, 2, 3],     [3, 4, 5],     [5, 6, 7],     [7, 8, 9],     [1, 1, 1],     [2, 2, 2],     [3, 3, 3],     [4, 4, 4],     [5, 5, 5],     [6, 6, 6]     ]; for (i = [0:num-1])     translate([locs[i, 0], locs[i, 1], locs[i, 2]])    // <===== error here         sphere(d = sd);
F
fred
Mon, Feb 27, 2023 9:45 PM

This is the first time I've experienced a list of vectors, but a little bit of fumbling around appears to make it work:
for (i = [0:num-1])
translate(locs[i])
        sphere(d = sd);

On Monday, February 27, 2023 at 04:24:29 PM EST, jon <jon@jonbondy.com> wrote:  

I tried to make a list of 3D locations (x, y, z) and then reference them
in a loop.  Clearly, I do not understand how to reference the elements
of a list.

sd = 0.5;    // sphere diameter
num = 10;    // number of x/y/z triplets
locs = [
    [1, 2, 3],
    [3, 4, 5],
    [5, 6, 7],
    [7, 8, 9],
    [1, 1, 1],
    [2, 2, 2],
    [3, 3, 3],
    [4, 4, 4],
    [5, 5, 5],
    [6, 6, 6]
    ];

for (i = [0:num-1])
    translate([locs[i, 0], locs[i, 1], locs[i, 2]])    // <===== error here
        sphere(d = sd);


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

This is the first time I've experienced a list of vectors, but a little bit of fumbling around appears to make it work: for (i = [0:num-1]) translate(locs[i])         sphere(d = sd); On Monday, February 27, 2023 at 04:24:29 PM EST, jon <jon@jonbondy.com> wrote: I tried to make a list of 3D locations (x, y, z) and then reference them in a loop.  Clearly, I do not understand how to reference the elements of a list. sd = 0.5;    // sphere diameter num = 10;    // number of x/y/z triplets locs = [     [1, 2, 3],     [3, 4, 5],     [5, 6, 7],     [7, 8, 9],     [1, 1, 1],     [2, 2, 2],     [3, 3, 3],     [4, 4, 4],     [5, 5, 5],     [6, 6, 6]     ]; for (i = [0:num-1])     translate([locs[i, 0], locs[i, 1], locs[i, 2]])    // <===== error here         sphere(d = sd); _______________________________________________ OpenSCAD mailing list To unsubscribe send an email to discuss-leave@lists.openscad.org
KT
Kevin Toppenberg
Mon, Feb 27, 2023 9:47 PM

Finally, something I might be able to help with:

locs[i] would be a reference to the relative vector.  So use this:
sd = 0.5;    // sphere diameter
num = 10;    // number of x/y/z triplets
locs = [
[1, 2, 3],
[3, 4, 5],
[5, 6, 7],
[7, 8, 9],
[1, 1, 1],
[2, 2, 2],
[3, 3, 3],
[4, 4, 4],
[5, 5, 5],
[6, 6, 6]
];

for (i = [0:1:len(locs)-1])
translate(locs[i])
sphere(d = sd);

On Mon, Feb 27, 2023 at 4:23 PM jon jon@jonbondy.com wrote:

I tried to make a list of 3D locations (x, y, z) and then reference them
in a loop.  Clearly, I do not understand how to reference the elements
of a list.

sd = 0.5;    // sphere diameter
num = 10;    // number of x/y/z triplets
locs = [
[1, 2, 3],
[3, 4, 5],
[5, 6, 7],
[7, 8, 9],
[1, 1, 1],
[2, 2, 2],
[3, 3, 3],
[4, 4, 4],
[5, 5, 5],
[6, 6, 6]
];

for (i = [0:num-1])
translate([locs[i, 0], locs[i, 1], locs[i, 2]])    // <===== error
here
sphere(d = sd);


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

Finally, something I might be able to help with: locs[i] would be a reference to the relative vector. So use this: sd = 0.5; // sphere diameter num = 10; // number of x/y/z triplets locs = [ [1, 2, 3], [3, 4, 5], [5, 6, 7], [7, 8, 9], [1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5], [6, 6, 6] ]; for (i = [0:1:len(locs)-1]) translate(locs[i]) sphere(d = sd); On Mon, Feb 27, 2023 at 4:23 PM jon <jon@jonbondy.com> wrote: > I tried to make a list of 3D locations (x, y, z) and then reference them > in a loop. Clearly, I do not understand how to reference the elements > of a list. > > > sd = 0.5; // sphere diameter > num = 10; // number of x/y/z triplets > locs = [ > [1, 2, 3], > [3, 4, 5], > [5, 6, 7], > [7, 8, 9], > [1, 1, 1], > [2, 2, 2], > [3, 3, 3], > [4, 4, 4], > [5, 5, 5], > [6, 6, 6] > ]; > > for (i = [0:num-1]) > translate([locs[i, 0], locs[i, 1], locs[i, 2]]) // <===== error > here > sphere(d = sd); > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
J
jon
Mon, Feb 27, 2023 9:50 PM

Thanks, Fred and Kevin!  Obvious once I saw it!

Jon

On 2/27/2023 4:47 PM, Kevin Toppenberg wrote:

Finally, something I might be able to help with:

locs[i] would be a reference to the relative vector.  So use this:
sd = 0.5;    // sphere diameter
num = 10;    // number of x/y/z triplets
locs = [
     [1, 2, 3],
     [3, 4, 5],
     [5, 6, 7],
     [7, 8, 9],
     [1, 1, 1],
     [2, 2, 2],
     [3, 3, 3],
     [4, 4, 4],
     [5, 5, 5],
     [6, 6, 6]
     ];

for (i = [0:1:len(locs)-1])
     translate(locs[i])
         sphere(d = sd);

On Mon, Feb 27, 2023 at 4:23 PM jon jon@jonbondy.com wrote:

 I tried to make a list of 3D locations (x, y, z) and then
 reference them
 in a loop.  Clearly, I do not understand how to reference the
 elements
 of a list.


 sd = 0.5;    // sphere diameter
 num = 10;    // number of x/y/z triplets
 locs = [
      [1, 2, 3],
      [3, 4, 5],
      [5, 6, 7],
      [7, 8, 9],
      [1, 1, 1],
      [2, 2, 2],
      [3, 3, 3],
      [4, 4, 4],
      [5, 5, 5],
      [6, 6, 6]
      ];

 for (i = [0:num-1])
      translate([locs[i, 0], locs[i, 1], locs[i, 2]])    // <=====
 error here
          sphere(d = sd);
 _______________________________________________
 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

Thanks, Fred and Kevin!  Obvious once I saw it! Jon On 2/27/2023 4:47 PM, Kevin Toppenberg wrote: > Finally, something I might be able to help with: > > locs[i] would be a reference to the relative vector.  So use this: > sd = 0.5;    // sphere diameter > num = 10;    // number of x/y/z triplets > locs = [ >      [1, 2, 3], >      [3, 4, 5], >      [5, 6, 7], >      [7, 8, 9], >      [1, 1, 1], >      [2, 2, 2], >      [3, 3, 3], >      [4, 4, 4], >      [5, 5, 5], >      [6, 6, 6] >      ]; > > for (i = [0:1:len(locs)-1]) >      translate(locs[i]) >          sphere(d = sd); > > > On Mon, Feb 27, 2023 at 4:23 PM jon <jon@jonbondy.com> wrote: > > I tried to make a list of 3D locations (x, y, z) and then > reference them > in a loop.  Clearly, I do not understand how to reference the > elements > of a list. > > > sd = 0.5;    // sphere diameter > num = 10;    // number of x/y/z triplets > locs = [ >      [1, 2, 3], >      [3, 4, 5], >      [5, 6, 7], >      [7, 8, 9], >      [1, 1, 1], >      [2, 2, 2], >      [3, 3, 3], >      [4, 4, 4], >      [5, 5, 5], >      [6, 6, 6] >      ]; > > for (i = [0:num-1]) >      translate([locs[i, 0], locs[i, 1], locs[i, 2]])    // <===== > error here >          sphere(d = sd); > _______________________________________________ > 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
NH
nop head
Mon, Feb 27, 2023 10:35 PM

Or, more simply:

sd = 0.5;    // sphere diameter
locs = [
[1, 2, 3],
[3, 4, 5],
[5, 6, 7],
[7, 8, 9],
[1, 1, 1],
[2, 2, 2],
[3, 3, 3],
[4, 4, 4],
[5, 5, 5],
[6, 6, 6]
];

for (pos = locs)
translate(pos)
sphere(d = sd);

On Mon, 27 Feb 2023 at 21:50, jon jon@jonbondy.com wrote:

Thanks, Fred and Kevin!  Obvious once I saw it!

Jon

On 2/27/2023 4:47 PM, Kevin Toppenberg wrote:

Finally, something I might be able to help with:

locs[i] would be a reference to the relative vector.  So use this:
sd = 0.5;    // sphere diameter
num = 10;    // number of x/y/z triplets
locs = [
[1, 2, 3],
[3, 4, 5],
[5, 6, 7],
[7, 8, 9],
[1, 1, 1],
[2, 2, 2],
[3, 3, 3],
[4, 4, 4],
[5, 5, 5],
[6, 6, 6]
];

for (i = [0:1:len(locs)-1])
translate(locs[i])
sphere(d = sd);

On Mon, Feb 27, 2023 at 4:23 PM jon jon@jonbondy.com wrote:

I tried to make a list of 3D locations (x, y, z) and then reference them
in a loop.  Clearly, I do not understand how to reference the elements
of a list.

sd = 0.5;    // sphere diameter
num = 10;    // number of x/y/z triplets
locs = [
[1, 2, 3],
[3, 4, 5],
[5, 6, 7],
[7, 8, 9],
[1, 1, 1],
[2, 2, 2],
[3, 3, 3],
[4, 4, 4],
[5, 5, 5],
[6, 6, 6]
];

for (i = [0:num-1])
translate([locs[i, 0], locs[i, 1], locs[i, 2]])    // <===== error
here
sphere(d = sd);


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

Or, more simply: sd = 0.5; // sphere diameter locs = [ [1, 2, 3], [3, 4, 5], [5, 6, 7], [7, 8, 9], [1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5], [6, 6, 6] ]; for (pos = locs) translate(pos) sphere(d = sd); On Mon, 27 Feb 2023 at 21:50, jon <jon@jonbondy.com> wrote: > Thanks, Fred and Kevin! Obvious once I saw it! > > Jon > > > On 2/27/2023 4:47 PM, Kevin Toppenberg wrote: > > Finally, something I might be able to help with: > > locs[i] would be a reference to the relative vector. So use this: > sd = 0.5; // sphere diameter > num = 10; // number of x/y/z triplets > locs = [ > [1, 2, 3], > [3, 4, 5], > [5, 6, 7], > [7, 8, 9], > [1, 1, 1], > [2, 2, 2], > [3, 3, 3], > [4, 4, 4], > [5, 5, 5], > [6, 6, 6] > ]; > > for (i = [0:1:len(locs)-1]) > translate(locs[i]) > sphere(d = sd); > > > On Mon, Feb 27, 2023 at 4:23 PM jon <jon@jonbondy.com> wrote: > >> I tried to make a list of 3D locations (x, y, z) and then reference them >> in a loop. Clearly, I do not understand how to reference the elements >> of a list. >> >> >> sd = 0.5; // sphere diameter >> num = 10; // number of x/y/z triplets >> locs = [ >> [1, 2, 3], >> [3, 4, 5], >> [5, 6, 7], >> [7, 8, 9], >> [1, 1, 1], >> [2, 2, 2], >> [3, 3, 3], >> [4, 4, 4], >> [5, 5, 5], >> [6, 6, 6] >> ]; >> >> for (i = [0:num-1]) >> translate([locs[i, 0], locs[i, 1], locs[i, 2]]) // <===== error >> here >> sphere(d = sd); >> _______________________________________________ >> 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 >
J
jon
Mon, Feb 27, 2023 10:49 PM

nop head:

Thanks!  Even better!

On 2/27/2023 5:35 PM, nop head wrote:

Or, more simply:

sd = 0.5;    // sphere diameter
locs = [
     [1, 2, 3],
     [3, 4, 5],
     [5, 6, 7],
     [7, 8, 9],
     [1, 1, 1],
     [2, 2, 2],
     [3, 3, 3],
     [4, 4, 4],
     [5, 5, 5],
     [6, 6, 6]
     ];

for (pos = locs)
     translate(pos)
         sphere(d = sd);

nop head: Thanks!  Even better! On 2/27/2023 5:35 PM, nop head wrote: > Or, more simply: > > sd = 0.5;    // sphere diameter > locs = [ >      [1, 2, 3], >      [3, 4, 5], >      [5, 6, 7], >      [7, 8, 9], >      [1, 1, 1], >      [2, 2, 2], >      [3, 3, 3], >      [4, 4, 4], >      [5, 5, 5], >      [6, 6, 6] >      ]; > > for (pos = locs) >      translate(pos) >          sphere(d = sd); >