Discussion:
[OpenSCAD] for loop implicid union.
Rogier Wolff
2018-09-01 08:45:23 UTC
Permalink
Hi,

I have this puzzle I'm making:
makepuzzle (pitch=35, theblock = bn, real=1)
{
rotate ([ 0, 0, 0]) beam (r=bs, height=bl);
rotate ([ 0,180, 0]) beam (r=bs, height=bl);
rotate ([ 0, 90, 90]) beam (r=bs, height=bl);
rotate ([ 0,-90,-90]) beam (r=bs, height=bl);
rotate ([ 90, 0, 90]) beam (r=bs, height=bl);
rotate ([-90, 0,-90]) beam (r=bs, height=bl);
}

where I would like to have the list-of-rotations available elsewhere.

So I'm going towards:

makepuzzle (pitch=35, theblock = bn, real=1)
for (i=[0:5])
rotate (lor[i]) beam (r=bs, height=bl);

(lor is the list-of-rotations).

but now the "makepuzzle" module has only one child because for does an
implicit union. And makepuzzle needs access to all the six
children....

IMHO this is why the "implicit" anything is not a good idea. In pascal
there is the "writeln" with the implicit newline. As a building block
you cannot make a "write" out of that, but the other way around you
can easily make a writeln out of "write".

Similarly here: If you want a union of your for loop you can easily
add the union in front, but the other way around is difficult. Or at
least not obvious how to do it for me.

Roger.
--
** ***@BitWizard.nl ** http://www.BitWizard.nl/ ** +31-15-2600998 **
** Delftechpark 26 2628 XH Delft, The Netherlands. KVK: 27239233 **
*-- BitWizard writes Linux device drivers for any device you may have! --*
The plan was simple, like my brother-in-law Phil. But unlike
Phil, this plan just might work.
nop head
2018-09-01 09:11:16 UTC
Permalink
Yes its a major problem but it isn't just for loops. Any openscad module,
like translate(), etc, can only return one child, so it has to union its
results.

The only way to get more than one child is to have a list in braces
directly after the object with the children() statements. You can't even
pass them on because children() being a module only ever returns one node.

I believe there is work in progress to fix this.
Post by Rogier Wolff
Hi,
makepuzzle (pitch=35, theblock = bn, real=1)
{
rotate ([ 0, 0, 0]) beam (r=bs, height=bl);
rotate ([ 0,180, 0]) beam (r=bs, height=bl);
rotate ([ 0, 90, 90]) beam (r=bs, height=bl);
rotate ([ 0,-90,-90]) beam (r=bs, height=bl);
rotate ([ 90, 0, 90]) beam (r=bs, height=bl);
rotate ([-90, 0,-90]) beam (r=bs, height=bl);
}
where I would like to have the list-of-rotations available elsewhere.
makepuzzle (pitch=35, theblock = bn, real=1)
for (i=[0:5])
rotate (lor[i]) beam (r=bs, height=bl);
(lor is the list-of-rotations).
but now the "makepuzzle" module has only one child because for does an
implicit union. And makepuzzle needs access to all the six
children....
IMHO this is why the "implicit" anything is not a good idea. In pascal
there is the "writeln" with the implicit newline. As a building block
you cannot make a "write" out of that, but the other way around you
can easily make a writeln out of "write".
Similarly here: If you want a union of your for loop you can easily
add the union in front, but the other way around is difficult. Or at
least not obvious how to do it for me.
Roger.
--
** Delftechpark 26 2628 XH Delft, The Netherlands. KVK: 27239233 **
*-- BitWizard writes Linux device drivers for any device you may have! --*
The plan was simple, like my brother-in-law Phil. But unlike
Phil, this plan just might work.
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Rogier Wolff
2018-09-01 18:48:22 UTC
Permalink
Post by nop head
Yes its a major problem but it isn't just for loops. Any openscad module,
like translate(), etc, can only return one child, so it has to union its
results.
Post by Rogier Wolff
Hi,
makepuzzle (pitch=35, theblock = bn, real=1)
{
rotate ([ 0, 0, 0]) beam (r=bs, height=bl);
rotate ([ 0,180, 0]) beam (r=bs, height=bl);
rotate ([ 0, 90, 90]) beam (r=bs, height=bl);
rotate ([ 0,-90,-90]) beam (r=bs, height=bl);
rotate ([ 90, 0, 90]) beam (r=bs, height=bl);
rotate ([-90, 0,-90]) beam (r=bs, height=bl);
}
I have found a reasonably elegant solution to my problem:

I have now the "one beam" module do the rotations (and colors)

So.. I'd like to use a loop here, but can't.
makepuzzle (pitch=35, theblock = bn, real=1) {
onebeam (0);
onebeam (1);
onebeam (2);
onebeam (3);
onebeam (4);
onebeam (5);
}

I'm working on a design where the number of pieces is not six, so
that'll be annoying. But other than that... things are looking good.


For printing I need to rotate the stuff back to a fixed orientation
so while forward rotation is:
rotate (lor[num]);
(list-of-rotations).

the inverse is:
module rrotate (v)
{
rotate ([-v[0],0,0])
rotate ([0,-v[1],0])
rotate ([0,0,-v[2]])
children ();
}


Roger.
--
** ***@BitWizard.nl ** http://www.BitWizard.nl/ ** +31-15-2600998 **
** Delftechpark 26 2628 XH Delft, The Netherlands. KVK: 27239233 **
*-- BitWizard writes Linux device drivers for any device you may have! --*
The plan was simple, like my brother-in-law Phil. But unlike
Phil, this plan just might work.
MichaelAtOz
2018-09-02 03:59:01 UTC
Permalink
Post by nop head
I believe there is work in progress to fix this.
May be a while <https://github.com/openscad/openscad/issues/350> , it needs
some neurons applied.



-----
Admin - email* me if you need anything, or if I've done something stupid...

* click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
--
Sent from: http://forum.openscad.org/

Loading...