discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Re: [OpenSCAD] Creating pie (pizza slice) shape (need a dynamic length array)

T
TLC123
Sun, Sep 16, 2018 3:38 PM
            module slice(r = 10, deg = 30) {
            fn=$fn!=0?$fn :round(deg/10);  degn=(deg%360);
            step=degn/fn;   start=min(degn ,0);  end=max(degn,0);
            polygon(
                concat(
                    [[0,0]],
                    [for(i=[start:step:end+step])  
                        [cos(min(end,i))*r,sin(min(end,i))*r]]  ));}

            slice(10, 130);

--
Sent from: http://forum.openscad.org/

module slice(r = 10, deg = 30) { fn=$fn!=0?$fn :round(deg/10); degn=(deg%360); step=degn/fn; start=min(degn ,0); end=max(degn,0); polygon( concat( [[0,0]], [for(i=[start:step:end+step]) [cos(min(end,i))*r,sin(min(end,i))*r]] ));} slice(10, 130); -- Sent from: http://forum.openscad.org/
TP
Torsten Paul
Sun, Sep 16, 2018 3:45 PM

On 09/16/2018 05:38 PM, TLC123 wrote:

              polygon(
                  concat(
                      [[0,0]],
                      [for(i=[start:step:end+step])
                          [cos(min(end,i))*r,sin(min(end,i))*r]]  ));} >

The concat() is not needed anymore with the latest list comprehension
updates. It's possible to combine multiple generator expressions
or just simple values, e.g.:

polygon([
[0,0],
for(i=[start:step:end+step]) [cos(min(end,i))*r,sin(min(end,i))*r]
]);

ciao,
Torsten.

On 09/16/2018 05:38 PM, TLC123 wrote: > polygon( > concat( > [[0,0]], > [for(i=[start:step:end+step]) > [cos(min(end,i))*r,sin(min(end,i))*r]] ));} > The concat() is not needed anymore with the latest list comprehension updates. It's possible to combine multiple generator expressions or just simple values, e.g.: polygon([ [0,0], for(i=[start:step:end+step]) [cos(min(end,i))*r,sin(min(end,i))*r] ]); ciao, Torsten.
T
TLC123
Sun, Sep 16, 2018 4:34 PM

Oh thanks. That really makes things more elegant.

            module slice(r = 10, deg = 30) { 
            fn=$fn!=0?$fn :round(deg/10);         degn=(deg%360); 
            step=degn/fn;   start=min(degn ,0);  end=max(degn,0); 
            polygon(r*[[0,0], for(i=[start:step:end]) [cos(i),

sin(i)]]);    }

            slice(10, 130);

--
Sent from: http://forum.openscad.org/

Oh thanks. That really makes things more elegant. module slice(r = 10, deg = 30) { fn=$fn!=0?$fn :round(deg/10); degn=(deg%360); step=degn/fn; start=min(degn ,0); end=max(degn,0); polygon(r*[[0,0], for(i=[start:step:end]) [cos(i), sin(i)]]); } slice(10, 130); -- Sent from: http://forum.openscad.org/