Re: OpenSCAD Digest, Vol 23, Issue 11

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: OpenSCAD Digest, Vol 23, Issue 11

Pierre Lecanu Wibee
On Saturday 22 October 2011 12:00:02 [hidden email] wrote:

> Send OpenSCAD mailing list submissions to
> [hidden email]
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://rocklinux.net/mailman/listinfo/openscad
> or, via email, send a message with subject or body 'help' to
> [hidden email]
>
> You can reach the person managing the list at
> [hidden email]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of OpenSCAD digest..."
>
>
> Today's Topics:
>
>    1. OpenSCAD two problems and futur documentation openscad and
>       openFoam (Pierre Lecanu Wibee)
>    2. Re: OpenSCAD two problems and futur documentation openscad
>       and openFoam (Brad Pitcher)
>    3. Re: OpenSCAD two problems and futur documentation openscad
>       and openFoam (Marius Kintel)
>    4. Re: OpenSCAD two problems and futur documentation openscad
>       and openFoam (Brad Pitcher)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Fri, 21 Oct 2011 17:16:50 +0200
> From: Pierre Lecanu Wibee <[hidden email]>
> Subject: [OpenSCAD] OpenSCAD two problems and futur documentation
> openscad and openFoam
> To: [hidden email]
> Message-ID: <[hidden email]>
> Content-Type: Text/Plain;  charset="iso-8859-1"
>
> Hello,
>
> I have two problem?
>
> First problem
>
> It is possible to create a array as
> a=1;
> b=2;
> array=[a,b];
>
>
>  it is possible to read the values
> echo(array[0]);
>
>
>
> it is impossible to create a new value in the array as
> array[2]=3;
>
>
>
>
> Second problem
>
>
> Is it possible of crer a function with a condition?
>
> function toto(i)= if (i=0) {return = [0];} else {return = [5];}
> echo(toto(3));
>
>
>
> I use openscad and openFoam
> openscad it's an excellent software
>
> I prepare a documentation to use openscad with openFoam
>
>
> best regard
>
> > Hello,
> >
> > I have two problem?
> >
> > First problem
> >
> > It is possible to create a array as
> > a=1;
> > b=2;
> > array=[a,b];
> >
> >  it is possible to read the values
> >
> > echo(array[0]);
> >
> >
> >
> > it is impossible to create a new value in the array as
> > array[2]=3;
> >
> >
> >
> >
> > Second problem
> >
> >
> > Is it possible of crer a function with a condition?
> >
> > function toto(i)= if (i=0) {return = [0];} else {return = [5];}
> > echo(toto(3));
> >
> >
> >
> > I use openscad and openFoam
> > openscad it's an excellent software
> >
> > I prepare a documentation to use openscad with openFoam
> >
> >
> > best regard
> >
> >
> > --
> > Cordialement
> >
> > Pierre Lecanu
> > @wibee.eu
> >
> >
> > _______________________________________________
> > OpenSCAD mailing list
> > [hidden email]
> > http://rocklinux.net/mailman/listinfo/openscad
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://rocklinux.net/pipermail/openscad/attachments/20111021/95998915/atta
> chment-0001.html
>
> ------------------------------
>
> Message: 3
> Date: Fri, 21 Oct 2011 19:25:00 +0200
> From: Marius Kintel <[hidden email]>
> Subject: Re: [OpenSCAD] OpenSCAD two problems and futur documentation
> openscad and openFoam
> To: [hidden email]
> Message-ID: <[hidden email]>
> Content-Type: text/plain; charset=us-ascii
>
> On Oct 21, 2011, at 17:16 PM, Pierre Lecanu Wibee wrote:
> > it is impossible to create a new value in the array as
> > array[2]=3;
>
> At the moment, this is not possible in OpenSCAD.
>
> > Is it possible of crer a function with a condition?
> >
> > function toto(i)= if (i=0) {return = [0];} else {return = [5];}
>
> function toto(i) = (i == 0) ? [0] : [5];
>
>  -Marius
>
>
>
> ------------------------------
>
> Message: 4
> Date: Fri, 21 Oct 2011 10:27:30 -0700
> From: Brad Pitcher <[hidden email]>
> Subject: Re: [OpenSCAD] OpenSCAD two problems and futur documentation
> openscad and openFoam
> To: [hidden email]
> Message-ID:
> <[hidden email]>
> Content-Type: text/plain; charset="iso-8859-1"
>
> > function toto(i) = (i == 0) ? [0] : [5];
> >
> > Whoops, yeah I forgot the double ==. Listen to Marius, not me
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://rocklinux.net/pipermail/openscad/attachments/20111021/0d43f2be/atta
> chment-0001.html
>
> ------------------------------
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://rocklinux.net/mailman/listinfo/openscad
>
>
> End of OpenSCAD Digest, Vol 23, Issue 11
> ****************************************
Thank you for the answer
I have a another question is it possible to create a fonction similar at this

function toto(k)= {sum =0; for(i=[0:k]) {sum=sum+i}; retrun sum; }


openscad creates clean files STL which is appropriate perfectly with openfoam.
it 's for this reason which I prepare a documentation to use openscad with
openfoam correctly.  



Like I don't  write well in English, I will address to you my document for
correction and diffusion

best regard


--
Cordialement

Pierre Lecanu
@wibee.eu

Reply | Threaded
Open this post in threaded view
|

Re: OpenSCAD Digest, Vol 23, Issue 11

Triffid Hunter
On Sun, Oct 23, 2011 at 7:08 PM, Pierre Lecanu Wibee <[hidden email]> wrote:
> function toto(k)= {sum =0; for(i=[0:k]) {sum=sum+i}; retrun sum; }

function toto(k) { return k + 1; }

Reply | Threaded
Open this post in threaded view
|

Re: OpenSCAD Digest, Vol 23, Issue 11

Giles Bathgate-2
> function toto(k) { return k + 1; }

Syntax error you want:

  function toto(k) = k+1;

Regards

Giles

Reply | Threaded
Open this post in threaded view
|

Re: OpenSCAD Digest, Vol 23, Issue 11

nophead
Surely it's an AP:
 
function toto(k) = (k+1) * k / 2;

But that steps round the issue that there are no loops inside functions.

On 23 October 2011 16:46, Giles Bathgate <[hidden email]> wrote:
> function toto(k) { return k + 1; }

Syntax error you want:

 function toto(k) = k+1;

Regards

Giles
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad

Reply | Threaded
Open this post in threaded view
|

Re: OpenSCAD Digest, Vol 23, Issue 11

William Adams
But of course RapCAD can do this!
 
It sure would be useful if functions could have bodies, and recursion.  But, plenty can be done without it.
 
You just have to leave typical notions of programming behind, and just do your loops as part of a module, where instead of returning a result, you code up an object directly.
 
Another way OpenScad could be extended is if the child() module could give you access to the various attributes of an object.  In particular the points mesh.  Then I could stuff anything into the points mesh, and read it somewhere else.  This is similar to what GLSL did in the early days where 'texture' was just another name for 'random memory'.
 
-- William

===============================
- Shaping clay is easier than digging it out of the ground.

http://blog.nanotechstyles.com
http://www.thingiverse.com/WilliamAAdams
https://github.com/Wiladams
 

 

Date: Sun, 23 Oct 2011 16:55:36 +0100
From: [hidden email]
To: [hidden email]
Subject: Re: [OpenSCAD] OpenSCAD Digest, Vol 23, Issue 11

Surely it's an AP:
 
function toto(k) = (k+1) * k / 2;

But that steps round the issue that there are no loops inside functions.

On 23 October 2011 16:46, Giles Bathgate <[hidden email]> wrote:
> function toto(k) { return k + 1; }

Syntax error you want:

 function toto(k) = k+1;

Regards

Giles
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


_______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscad
Reply | Threaded
Open this post in threaded view
|

Re: OpenSCAD Digest, Vol 23, Issue 11

nophead
It appears that you can have recursions because if a function calls itself openscad crashes. But for some reason the ternary operator seems to not work on functions. Is that just a bug or is there a fundamental reason why it doesn't?

If it did you could solve the problem with

function toto(k) = k ? toto(k-1) + k : 0;

On 23 October 2011 17:47, William Adams <[hidden email]> wrote:
But of course RapCAD can do this!
 
It sure would be useful if functions could have bodies, and recursion.  But, plenty can be done without it.
 
You just have to leave typical notions of programming behind, and just do your loops as part of a module, where instead of returning a result, you code up an object directly.
 
Another way OpenScad could be extended is if the child() module could give you access to the various attributes of an object.  In particular the points mesh.  Then I could stuff anything into the points mesh, and read it somewhere else.  This is similar to what GLSL did in the early days where 'texture' was just another name for 'random memory'.
 
-- William

===============================
- Shaping clay is easier than digging it out of the ground.

http://blog.nanotechstyles.com
http://www.thingiverse.com/WilliamAAdams
https://github.com/Wiladams
 

 

Date: Sun, 23 Oct 2011 16:55:36 +0100
From: [hidden email]
To: [hidden email]
Subject: Re: [OpenSCAD] OpenSCAD Digest, Vol 23, Issue 11


Surely it's an AP:
 
function toto(k) = (k+1) * k / 2;

But that steps round the issue that there are no loops inside functions.

On 23 October 2011 16:46, Giles Bathgate <[hidden email]> wrote:
> function toto(k) { return k + 1; }

Syntax error you want:

 function toto(k) = k+1;

Regards

Giles
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


_______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscad

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


Reply | Threaded
Open this post in threaded view
|

Re: OpenSCAD Digest, Vol 23, Issue 11

Whosawhatsis
Are you sure that the ternary operator exists in OpenSCAD? I've tried to use it several times and it has never worked, forcing me to write a significantly longer script to code around it. I've never used a function in OpenSCAD (only modules), but if it doesn't work in functions, perhaps there are other situations where it would be very useful but doesn't work.

On Sunday, October 23, 2011 at 10:48 AM, nop head wrote:

It appears that you can have recursions because if a function calls itself openscad crashes. But for some reason the ternary operator seems to not work on functions. Is that just a bug or is there a fundamental reason why it doesn't?

If it did you could solve the problem with

function toto(k) = k ? toto(k-1) + k : 0;

On 23 October 2011 17:47, William Adams <[hidden email]> wrote:
But of course RapCAD can do this!
 
It sure would be useful if functions could have bodies, and recursion.  But, plenty can be done without it.
 
You just have to leave typical notions of programming behind, and just do your loops as part of a module, where instead of returning a result, you code up an object directly.
 
Another way OpenScad could be extended is if the child() module could give you access to the various attributes of an object.  In particular the points mesh.  Then I could stuff anything into the points mesh, and read it somewhere else.  This is similar to what GLSL did in the early days where 'texture' was just another name for 'random memory'.
 
-- William

===============================
- Shaping clay is easier than digging it out of the ground.

http://blog.nanotechstyles.com
http://www.thingiverse.com/WilliamAAdams
https://github.com/Wiladams
 

 

Date: Sun, 23 Oct 2011 16:55:36 +0100
From: [hidden email]
To: [hidden email]
Subject: Re: [OpenSCAD] OpenSCAD Digest, Vol 23, Issue 11


Surely it's an AP:
 
function toto(k) = (k+1) * k / 2;

But that steps round the issue that there are no loops inside functions.

On 23 October 2011 16:46, Giles Bathgate <[hidden email]> wrote:
> function toto(k) { return k + 1; }

Syntax error you want:

 function toto(k) = k+1;

Regards

Giles
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


_______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscad

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad

Reply | Threaded
Open this post in threaded view
|

Re: OpenSCAD Digest, Vol 23, Issue 11

nophead
Actually it does work. I forgot that you need a boolean. This works:

function toto(k) = k > 0 ? toto(k - 1) + k : 0;


On 23 October 2011 19:06, Whosawhatsis <[hidden email]> wrote:
Are you sure that the ternary operator exists in OpenSCAD? I've tried to use it several times and it has never worked, forcing me to write a significantly longer script to code around it. I've never used a function in OpenSCAD (only modules), but if it doesn't work in functions, perhaps there are other situations where it would be very useful but doesn't work.

On Sunday, October 23, 2011 at 10:48 AM, nop head wrote:

It appears that you can have recursions because if a function calls itself openscad crashes. But for some reason the ternary operator seems to not work on functions. Is that just a bug or is there a fundamental reason why it doesn't?

If it did you could solve the problem with

function toto(k) = k ? toto(k-1) + k : 0;

On 23 October 2011 17:47, William Adams <[hidden email]> wrote:
But of course RapCAD can do this!
 
It sure would be useful if functions could have bodies, and recursion.  But, plenty can be done without it.
 
You just have to leave typical notions of programming behind, and just do your loops as part of a module, where instead of returning a result, you code up an object directly.
 
Another way OpenScad could be extended is if the child() module could give you access to the various attributes of an object.  In particular the points mesh.  Then I could stuff anything into the points mesh, and read it somewhere else.  This is similar to what GLSL did in the early days where 'texture' was just another name for 'random memory'.
 
-- William

===============================
- Shaping clay is easier than digging it out of the ground.

http://blog.nanotechstyles.com
http://www.thingiverse.com/WilliamAAdams
https://github.com/Wiladams
 

 

Date: Sun, 23 Oct 2011 16:55:36 +0100
From: [hidden email]
To: [hidden email]
Subject: Re: [OpenSCAD] OpenSCAD Digest, Vol 23, Issue 11


Surely it's an AP:
 
function toto(k) = (k+1) * k / 2;

But that steps round the issue that there are no loops inside functions.

On 23 October 2011 16:46, Giles Bathgate <[hidden email]> wrote:
> function toto(k) { return k + 1; }

Syntax error you want:

 function toto(k) = k+1;

Regards

Giles
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


_______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscad

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


Reply | Threaded
Open this post in threaded view
|

Re: OpenSCAD Digest, Vol 23, Issue 11

nophead
And I seem to remember reading somewhere that any loop can be converted to tail recursion, so it would seem to be a complete solution for iteration in functions.

On 23 October 2011 19:14, nop head <[hidden email]> wrote:
Actually it does work. I forgot that you need a boolean. This works:

function toto(k) = k > 0 ? toto(k - 1) + k : 0;


On 23 October 2011 19:06, Whosawhatsis <[hidden email]> wrote:
Are you sure that the ternary operator exists in OpenSCAD? I've tried to use it several times and it has never worked, forcing me to write a significantly longer script to code around it. I've never used a function in OpenSCAD (only modules), but if it doesn't work in functions, perhaps there are other situations where it would be very useful but doesn't work.

On Sunday, October 23, 2011 at 10:48 AM, nop head wrote:

It appears that you can have recursions because if a function calls itself openscad crashes. But for some reason the ternary operator seems to not work on functions. Is that just a bug or is there a fundamental reason why it doesn't?

If it did you could solve the problem with

function toto(k) = k ? toto(k-1) + k : 0;

On 23 October 2011 17:47, William Adams <[hidden email]> wrote:
But of course RapCAD can do this!
 
It sure would be useful if functions could have bodies, and recursion.  But, plenty can be done without it.
 
You just have to leave typical notions of programming behind, and just do your loops as part of a module, where instead of returning a result, you code up an object directly.
 
Another way OpenScad could be extended is if the child() module could give you access to the various attributes of an object.  In particular the points mesh.  Then I could stuff anything into the points mesh, and read it somewhere else.  This is similar to what GLSL did in the early days where 'texture' was just another name for 'random memory'.
 
-- William

===============================
- Shaping clay is easier than digging it out of the ground.

http://blog.nanotechstyles.com
http://www.thingiverse.com/WilliamAAdams
https://github.com/Wiladams
 

 

Date: Sun, 23 Oct 2011 16:55:36 +0100
From: [hidden email]
To: [hidden email]
Subject: Re: [OpenSCAD] OpenSCAD Digest, Vol 23, Issue 11


Surely it's an AP:
 
function toto(k) = (k+1) * k / 2;

But that steps round the issue that there are no loops inside functions.

On 23 October 2011 16:46, Giles Bathgate <[hidden email]> wrote:
> function toto(k) { return k + 1; }

Syntax error you want:

 function toto(k) = k+1;

Regards

Giles
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


_______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscad

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad



Reply | Threaded
Open this post in threaded view
|

Re: OpenSCAD Digest, Vol 23, Issue 11

William Adams
More examples of ternary:

function map_array(range, u) = (u*range) >= range ? range-1 : floor(u*range);



and cascaded functions, with ternaries, that themselves call inbuilt functions, but not themselves:

function SSCos(shape, phi) = pow( abs(cos(shape[0]*phi/4) / shape[4]), shape[2]);
function SSSin(shape, phi) = pow(abs(sin(shape[0]*phi/4) / shape[5]), shape[3]);
function SSR(shape, phi) = pow((SSCos(shape,phi) + SSSin(shape,phi)), 1/shape[1]);

function _EvalSuperShape2D3(phi, r) =
abs(r) == 0 ? [0,0,0] : [1/r * cos(phi), 1/r*sin(phi),0];



function _EvalSuperShape2D2(phi, n1, t1, t2) =


_EvalSuperShape2D3(phi, t1, t2, r=pow(t1+t2, 1/n1));


function EvalSuperShape2D(shape, phi) = _EvalSuperShape2D2(phi, shape[1], t1=SSCos(shape,phi), t2=SSSin(shape,phi));


I've thought about tail recursion as a mechanism for unrolling loops, but haven't figured out a way to express that in OpenScad.


Any ideas?


-- William


===============================
- Shaping clay is easier than digging it out of the ground.

http://blog.nanotechstyles.com
http://www.thingiverse.com/WilliamAAdams
https://github.com/Wiladams
 



Date: Sun, 23 Oct 2011 19:17:02 +0100
From: [hidden email]
To: [hidden email]
Subject: Re: [OpenSCAD] OpenSCAD Digest, Vol 23, Issue 11

And I seem to remember reading somewhere that any loop can be converted to tail recursion, so it would seem to be a complete solution for iteration in functions.

On 23 October 2011 19:14, nop head <[hidden email]> wrote:
Actually it does work. I forgot that you need a boolean. This works:

function toto(k) = k > 0 ? toto(k - 1) + k : 0;


On 23 October 2011 19:06, Whosawhatsis <[hidden email]> wrote:
Are you sure that the ternary operator exists in OpenSCAD? I've tried to use it several times and it has never worked, forcing me to write a significantly longer script to code around it. I've never used a function in OpenSCAD (only modules), but if it doesn't work in functions, perhaps there are other situations where it would be very useful but doesn't work.

On Sunday, October 23, 2011 at 10:48 AM, nop head wrote:

It appears that you can have recursions because if a function calls itself openscad crashes. But for some reason the ternary operator seems to not work on functions. Is that just a bug or is there a fundamental reason why it doesn't?

If it did you could solve the problem with

function toto(k) = k ? toto(k-1) + k : 0;

On 23 October 2011 17:47, William Adams <[hidden email]> wrote:
But of course RapCAD can do this!
 
It sure would be useful if functions could have bodies, and recursion.  But, plenty can be done without it.
 
You just have to leave typical notions of programming behind, and just do your loops as part of a module, where instead of returning a result, you code up an object directly.
 
Another way OpenScad could be extended is if the child() module could give you access to the various attributes of an object.  In particular the points mesh.  Then I could stuff anything into the points mesh, and read it somewhere else.  This is similar to what GLSL did in the early days where 'texture' was just another name for 'random memory'.
 
-- William

===============================
- Shaping clay is easier than digging it out of the ground.

http://blog.nanotechstyles.com
http://www.thingiverse.com/WilliamAAdams
https://github.com/Wiladams
 

 

Date: Sun, 23 Oct 2011 16:55:36 +0100
From: [hidden email]
To: [hidden email]
Subject: Re: [OpenSCAD] OpenSCAD Digest, Vol 23, Issue 11


Surely it's an AP:
 
function toto(k) = (k+1) * k / 2;

But that steps round the issue that there are no loops inside functions.

On 23 October 2011 16:46, Giles Bathgate <[hidden email]> wrote:
> function toto(k) { return k + 1; }

Syntax error you want:

 function toto(k) = k+1;

Regards

Giles
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


_______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscad

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad




_______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscad
Reply | Threaded
Open this post in threaded view
|

Re: OpenSCAD Digest, Vol 23, Issue 11

kintel
Administrator
In reply to this post by nophead

On Oct 23, 2011, at 20:14 PM, nop head wrote:

> Actually it does work. I forgot that you need a boolean. This works:
>
> function toto(k) = k > 0 ? toto(k - 1) + k : 0;
>
This was an oversight. You can now use any expression. The value will be converted to bool in the same way as for if/else.

 -Marius