[OpenSCAD] Computing polygon by function?

Michael Reifenberger mike at reifenberger.com
Mon Aug 22 22:40:45 CEST 2011


Hi,
thanks to all who replied so far!

Unfortunately the quick-and-dirty way of generating the pre-calculated polygon
by matlab/octave/excel is exactly that what I wanted to avoid.
I want to keep the logic self-contained and flexible to be able to adapt
the solids for many different dimentions quickly.

I'd need either:
...
PI=180;
INC=0.5;
oldx = 0; newx = 0; oldr = 0; newr = 0;
function x(b) = b;
function r(b) = abs(sin(b));
for (b = [0:INC:PI]) {
   if( b != 0 ) {
     newx=x(b), newr=r(b);
     rotate_extrude($fn=50)
       polygon( points=[[newx, newr],[oldx,oldr]] );
     oldx = newx, oldr = newr;
   }else{
     oldx = x(0), oldr = r(0);
   }
}
...

Or something like:
...
PI=180;
INC=0.5;
function x(b) = b;
function r(b) = abs(sin(b));
function foo() = {
   return = [[]];
   for (b = [0:INC:PI]) {
     return += [ x(b), r(b) ];
   }
   return(return);
}
rotate_extrude($fn=50)
   polygon( points=foo() );
...

Thanks anyway!

On Mon, 22 Aug 2011, Giles Bathgate wrote:

> Date: Mon, 22 Aug 2011 19:57:09 +0100
> From: Giles Bathgate <giles.bathgate at gmail.com>
> Reply-To: openscad at rocklinux.org
> To: openscad at rocklinux.org
> Subject: Re: [OpenSCAD] Computing polygon by function?
> 
> On 22 August 2011 14:53, Michael Reifenberger <mike at reifenberger.com> wrote:
>> Can a OpenSCAD function return a list of points generated inside a loop?
>
> I think the limitation stopping you from doing this is the ability to
> create a dynamic array/vector
>
> i.e. you cannot resize or append elements to an array.
>
> If you want a quick fix, do the math in a spreadsheet application to
> generate the list of points required and use the existing polygon
> module to realise your pointset.
>
> http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_the_2D_Subsystem#polygon
>
> Regards
>
> Giles
> _______________________________________________
> OpenSCAD mailing list
> OpenSCAD at rocklinux.org
> http://rocklinux.net/mailman/listinfo/openscad
>

Bye/2
---
Michael Reifenberger
Michael at Reifenberger.com
http://www.Reifenberger.com



More information about the OpenSCAD mailing list