JJ
Johan Jonker
Sat, Nov 12, 2016 2:23 PM
Johan_s_examples.scad
http://forum.openscad.org/file/n19053/Johan_s_examples.scad
Hello
I try to make some simple examples for myself to have some easy to copy and
past starts for new objects. While doing that I like also to define some
solutions and tricks. But not all of them are working. Maybe someone has
some suggestions.
- dynamic FOR statement
What I sometimes miss is a While loop where the variable has a more dynamic
delta than the fixed one in a for loop. This is a simple way I use to fix
that:
Or in a function:
In fact what I want to make is this:
--
View this message in context: http://forum.openscad.org/dynamic-FOR-statement-tp19053.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Johan_s_examples.scad
<http://forum.openscad.org/file/n19053/Johan_s_examples.scad>
Hello
I try to make some simple examples for myself to have some easy to copy and
past starts for new objects. While doing that I like also to define some
solutions and tricks. But not all of them are working. Maybe someone has
some suggestions.
1) dynamic FOR statement
What I sometimes miss is a While loop where the variable has a more dynamic
delta than the fixed one in a for loop. This is a simple way I use to fix
that:
Or in a function:
In fact what I want to make is this:
--
View this message in context: http://forum.openscad.org/dynamic-FOR-statement-tp19053.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
R
Ronaldo
Sat, Nov 12, 2016 2:43 PM
Jon,
The "dynamic for statement" and, at least, some forms of "multiple vectors
in a function" are already possible with the snapshot version extensions to
list comprehension
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/WIP#Overview .
for (h=[ each [0:1:10], each [10:10:1000], each [1000:1:1010] ])
--
View this message in context: http://forum.openscad.org/dynamic-FOR-statement-tp19053p19054.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Jon,
The "dynamic for statement" and, at least, some forms of "multiple vectors
in a function" are already possible with the snapshot version extensions to
list comprehension
<https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/WIP#Overview> .
for (h=[ each [0:1:10], each [10:10:1000], each [1000:1:1010] ])
--
View this message in context: http://forum.openscad.org/dynamic-FOR-statement-tp19053p19054.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
N
nophead
Sat, Nov 12, 2016 3:10 PM
You can do this:
for(r=[[0:1:10],[10:10:1000],[1000:1:1010]], h = r)
echo(h);
I.e. r iterates through a list of ranges and h iterates through each range.
--
View this message in context: http://forum.openscad.org/dynamic-FOR-statement-tp19053p19055.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
You can do this:
for(r=[[0:1:10],[10:10:1000],[1000:1:1010]], h = r)
echo(h);
I.e. r iterates through a list of ranges and h iterates through each range.
--
View this message in context: http://forum.openscad.org/dynamic-FOR-statement-tp19053p19055.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
JJ
Johan Jonker
Sat, Nov 12, 2016 4:58 PM
thanks!
Works excellent and the code is much more readable.
--
View this message in context: http://forum.openscad.org/dynamic-FOR-statement-tp19053p19056.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
thanks!
Works excellent and the code is much more readable.
--
View this message in context: http://forum.openscad.org/dynamic-FOR-statement-tp19053p19056.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
P
Parkinbot
Sat, Nov 12, 2016 5:15 PM
function circle(R,N) =
[ each for (w = [0:round(360/N):359])
(w<90)? [[Rcos(w),Rsin(w)]]:
(w<180)? [[Rcos(w),Rsin(w)]]:
(w==180)?
[[Rcos(w),Rsin(w)],[Rcos(w)+1,Rsin(w)],[Rcos(w)+1,Rsin(w)+1],[Rcos(w),Rsin(w)+1]]:
(w<270)? [[Rcos(w),Rsin(w)]]:
[[Rcos(w),Rsin(w)]]
];
and this works:
> function circle(R,N) =
> [ each for (w = [0:round(360/N):359])
> (w<90)? [[R*cos(w),R*sin(w)]]:
> (w<180)? [[R*cos(w),R*sin(w)]]:
> (w==180)?
> [[R*cos(w),R*sin(w)],[R*cos(w)+1,R*sin(w)],[R*cos(w)+1,R*sin(w)+1],[R*cos(w),R*sin(w)+1]]:
> (w<270)? [[R*cos(w),R*sin(w)]]:
> [[R*cos(w),R*sin(w)]]
> ];
--
View this message in context: http://forum.openscad.org/dynamic-FOR-statement-tp19053p19058.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
MK
Marius Kintel
Sat, Nov 12, 2016 5:37 PM
In terms of multiple vectors in a function: Since most of your cases are the same, you could also simplify it like this:
function circle(R,N) =
[ for (w = [0:round(360/N):359])
if (w==180) each [[Rcos(w),Rsin(w)],
[Rcos(w)+1,Rsin(w)],
[Rcos(w)+1,Rsin(w)+1],
[Rcos(w),Rsin(w)+1]]
else [Rcos(w),Rsin(w)]
];
The above code requires the experimental “lc-else” to be enabled (else clauses in list comprehensions).
-Marius
In terms of multiple vectors in a function: Since most of your cases are the same, you could also simplify it like this:
function circle(R,N) =
[ for (w = [0:round(360/N):359])
if (w==180) each [[R*cos(w),R*sin(w)],
[R*cos(w)+1,R*sin(w)],
[R*cos(w)+1,R*sin(w)+1],
[R*cos(w),R*sin(w)+1]]
else [R*cos(w),R*sin(w)]
];
The above code requires the experimental “lc-else” to be enabled (else clauses in list comprehensions).
-Marius
JJ
Johan Jonker
Sat, Nov 12, 2016 10:44 PM
Thanks for all these suggestions.
But I am sorry.
Syntax errors are reported when I use "each".
Do I have to install enhancements on the list comprehensions?
How do I do that and how do I activate them?
--
View this message in context: http://forum.openscad.org/dynamic-FOR-statement-tp19053p19060.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Thanks for all these suggestions.
But I am sorry.
Syntax errors are reported when I use "each".
Do I have to install enhancements on the list comprehensions?
How do I do that and how do I activate them?
--
View this message in context: http://forum.openscad.org/dynamic-FOR-statement-tp19053p19060.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
M
MichaelAtOz
Sat, Nov 12, 2016 11:54 PM
The above code requires the experimental “lc-else” to be enabled (else
clauses in list comprehensions).
and maybe the others, in Edit/Preferences/Features (in latest snapshot
version).
Admin - PM me if you need anything, or if I've done something stupid...
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!
View this message in context: http://forum.openscad.org/dynamic-FOR-statement-tp19053p19063.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Did you:
> The above code requires the experimental “lc-else” to be enabled (else
> clauses in list comprehensions).
and maybe the others, in Edit/Preferences/Features (in latest snapshot
version).
-----
Admin - PM me if you need anything, or if I've done something stupid...
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!
--
View this message in context: http://forum.openscad.org/dynamic-FOR-statement-tp19053p19063.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
R
runsun
Sun, Nov 13, 2016 1:07 AM
It seems that both Parkinbot and kintel's version produce 3 more points than
expected:
echo( len( circle_Parkinbot( 10,6)) ); //==> 9
echo( len( circle_Parkinbot( 10,12)) ); //==> 15
echo( len( circle_Parkinbot( 10,36)) ); //==> 39
echo( len( circle_Kintel( 10,6)) ); //==> 9
echo( len( circle_Kintel( 10,12)) ); //==> 15
echo( len( circle_Kintel( 10,36)) ); //==> 39
$ Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), synwrite ( 2 ); $ tips: hash ( 2 ), matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , tailRecur ( 2, 3 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ), text ; $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf )
View this message in context: http://forum.openscad.org/dynamic-FOR-statement-tp19053p19064.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
It seems that both Parkinbot and kintel's version produce 3 more points than
expected:
echo( len( circle_Parkinbot( 10,6)) ); //==> 9
echo( len( circle_Parkinbot( 10,12)) ); //==> 15
echo( len( circle_Parkinbot( 10,36)) ); //==> 39
echo( len( circle_Kintel( 10,6)) ); //==> 9
echo( len( circle_Kintel( 10,12)) ); //==> 15
echo( len( circle_Kintel( 10,36)) ); //==> 39
-----
$ Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), synwrite ( 2 ); $ tips: hash ( 2 ), matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , tailRecur ( 2, 3 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ), text ; $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf )
--
View this message in context: http://forum.openscad.org/dynamic-FOR-statement-tp19053p19064.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
R
runsun
Sun, Nov 13, 2016 1:31 AM
It seems that both Parkinbot and kintel's version produce 3 more points
than expected:
Maybe I missed something ?
$ Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), synwrite ( 2 ); $ tips: hash ( 2 ), matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , tailRecur ( 2, 3 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ), text ; $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf )
View this message in context: http://forum.openscad.org/dynamic-FOR-statement-tp19053p19065.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
runsun wrote
> It seems that both Parkinbot and kintel's version produce 3 more points
> than expected:
Maybe I missed something ?
-----
$ Runsun Pan, PhD $ libs: doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), synwrite ( 2 ); $ tips: hash ( 2 ), matrix ( 2 , 3 ), sweep ( 2 , 3 ), var ( 2 ), lerp , animation ( gif , prodVid , animlib ), precision ( 2 ), xl-control , type , rounded polygon , chfont , tailRecur ( 2, 3 ), isosphere ( 2 ), area , vol/center , RGB , CurvedImg , tests ( 2 ), text ; $ Apps: rollApp , blockscad , openjscad , on AWS ( pdf )
--
View this message in context: http://forum.openscad.org/dynamic-FOR-statement-tp19053p19065.html
Sent from the OpenSCAD mailing list archive at Nabble.com.