Creating pie (pizza slice) shape (need a dynamic length array) Classic List Threaded 29 messages 12
Open this post in threaded view
|

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

 Administrator On Sep 30, 2014, at 07:05 AM, QuackingPlums <[hidden email]> wrote: > > Can anyone explain why? There are no errors in the output window. > This is a bug - and it has since been fixed. The latest development snapshots should work. About code quoting: This is email, so as long as the plain-text content is good, you’re free to use any standard html which email readers understand. You’re probably better off using plain text though.  -Marius _______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscadhttp://openscad.org - https://flattr.com/thing/121566
Open this post in threaded view
|

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

 This post has NOT been accepted by the mailing list yet. This post was updated on . In reply to this post by clothbot Same in 3D: module cylinder_slice(r=3.0,h=10, a=30) {   \$fn=64;   intersection() {     cylinder(h=h,r=r);     cube([r,r,h]);     rotate(a-90) cube(r);   } } cylinder_slice(r=40,h=10,a=15);
Open this post in threaded view
|

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

 I wrote this code a while ago. It works with any angle by dynamically adding the necessary (small) number of subtracting triangles. module circular_sector(r, theta) {     overlap = 10;     dtheta = 360 - theta;     n = ceil(dtheta/90);     a = (dtheta+overlap*(n-1))/n;     difference() {         circle(r);         for (i=[0:1:n-1]) rotate([0,0,theta+i*(a-overlap)]) polygon([[0,0],[2*r,0],[2*r*cos(a),2*r*sin(a)]]);     } } -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

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

 In reply to this post by nophead It seems there are many versions of pie out there. In OpenScad it is always a good idea to avoid Boolean ops. Thus the following version is more basic. While it doesn't explicitly account for \$fs (indeed polygon() seems to enforce it), it copes well with \$fn, \$fa, and any - also negative - angles. pieSlice(10, 10, 23, \$fa=3); module pieSlice(r=10, start_angle=0, end_angle=45) {   polygon(pie(r, start_angle, end_angle));   function pie(r=40, a1=0, a2=150) =     let(start = a1%360)     let(end = (a2%360-start)>=0?a2%360:a2%360+360)     let(fa = \$fn==0?\$fa:360/\$fn)     let(step = (end-start)/ceil((end-start)/fa)- 1e-7)     r*[[0,0], for(i=[start:step:end]) [cos(i), sin(i)]]; } -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

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

Open this post in threaded view
|

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

 In reply to this post by Peter Uithoven                 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/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

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

 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. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org -- Torsten
Open this post in threaded view
|

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

 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/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org