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

29 messages
12
Open this post in threaded view
|

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

 Hi OpenSCAD people, I work a lot in 2D and I really mis a way to create a way to create a pie (pizza slice) shape. A workaround for me is the following function in which I create a circle and then remove parts of it with rectangles, but this is limited to whole quarters.  So my plan was to create a circle with a polygon, but then I need to create a array with a dynamic length (according to \$fn). For example, if \$fn is 3 I want to create (part of) a circle out of 3 points, but when it's 6 I need 6 points. Is there any way to do this?  Thanks in advance, Best regards,Peter Uithoven
Open this post in threaded view
|

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

 Hi Peter,Here's how I would approach the problem for pie slices of variable angle less than 90 degrees:--snip--module pie_slice(r=3.0,a=30) {  \$fn=64;  intersection() {    circle(r=r);    square(r);    rotate(a-90) square(r);  }}pie_slice(r=10,a=15);--end-snip--Andrew.On 2012-08-21, at 10:05 AM, Peter Uithoven wrote:Hi OpenSCAD people, I work a lot in 2D and I really mis a way to create a way to create a pie (pizza slice) shape. A workaround for me is the following function in which I create a circle and then remove parts of it with rectangles, but this is limited to whole quarters.  So my plan was to create a circle with a polygon, but then I need to create a array with a dynamic length (according to \$fn). For example, if \$fn is 3 I want to create (part of) a circle out of 3 points, but when it's 6 I need 6 points. Is there any way to do this?  Thanks in advance, Best regards,Peter Uithoven  _______________________________________________OpenSCAD mailing list[hidden email]http://rocklinux.net/mailman/listinfo/openscadhttp://openscad.org - https://flattr.com/thing/121566 --"The future is already here.  It's just not very evenly distributed" -- William GibsonMe: http://clothbot.com/wiki/
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 > A workaround for me is the following function in which I create a circle and > then remove parts of it with rectangles, but this is limited to whole quarters  If you rotate the rectangles then you can create any angle you need in the circle.  HTH, Ian
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 On Tue, 21 Aug 2012 16:05:05 +0200 Peter Uithoven <[hidden email]> wrote: > Hi OpenSCAD people, > > I work a lot in 2D and I really mis a way to create a way to create a pie > (pizza slice) shape. > > A workaround for me is the following function in which I create a circle > and then remove parts of it with rectangles, but this is limited to whole > quarters. Why not just remove a triangle from it ? Alan
Open this post in threaded view
|

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

 I think this is a general solution for any angle to any angle: module pie_slice(r, start_angle, end_angle) {     R = r * sqrt(2) + 1;     a0 = (4 * start_angle + 0 * end_angle) / 4;     a1 = (3 * start_angle + 1 * end_angle) / 4;     a2 = (2 * start_angle + 2 * end_angle) / 4;     a3 = (1 * start_angle + 3 * end_angle) / 4;     a4 = (0 * start_angle + 4 * end_angle) / 4;     if(end_angle > start_angle)         intersection() {         circle(r);         polygon([             [0,0],             [R * cos(a0), R * sin(a0)],             [R * cos(a1), R * sin(a1)],             [R * cos(a2), R * sin(a2)],             [R * cos(a3), R * sin(a3)],             [R * cos(a4), R * sin(a4)],             [0,0]        ]);     } } pie_slice(50, 40, 120); It works by covering the wanted bit of the circle with a fan of triangles, each 1/4 of the angle. That means the angle is no more than a right angle so the triangle edge boundary is made outside the circle by increasing the radius by sqrt(2) On 21 August 2012 15:36, Alan Cox wrote: On Tue, 21 Aug 2012 16:05:05 +0200 Peter Uithoven <[hidden email]> wrote: > Hi OpenSCAD people, > > I work a lot in 2D and I really mis a way to create a way to create a pie > (pizza slice) shape. > > A workaround for me is the following function in which I create a circle > and then remove parts of it with rectangles, but this is limited to whole > quarters. Why not just remove a triangle from it ? Alan _______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscad http://openscad.org - https://flattr.com/thing/121566
Open this post in threaded view
|

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

 A more concise version but contains an approximation to the point in the centre.module point(x,y) translate([x,y]) circle(0.01); module pie_slice(r, a0, a1) {     \$fa = 5;     R = r * sqrt(2) + 1;     intersection() {         circle(r);         hull() {             point(0,0);             for(i = [0:4])                 assign(a = ((4 - i) * a0 + i * a1) / 4)                      point(R * cos(a), R * sin(a));        }     } } pie_slice(50, 120, 40); On 21 August 2012 16:55, nop head wrote: I think this is a general solution for any angle to any angle: module pie_slice(r, start_angle, end_angle) {     R = r * sqrt(2) + 1;     a0 = (4 * start_angle + 0 * end_angle) / 4;     a1 = (3 * start_angle + 1 * end_angle) / 4;     a2 = (2 * start_angle + 2 * end_angle) / 4;     a3 = (1 * start_angle + 3 * end_angle) / 4;     a4 = (0 * start_angle + 4 * end_angle) / 4;     if(end_angle > start_angle)         intersection() {         circle(r);         polygon([             [0,0],             [R * cos(a0), R * sin(a0)],             [R * cos(a1), R * sin(a1)],             [R * cos(a2), R * sin(a2)],             [R * cos(a3), R * sin(a3)],             [R * cos(a4), R * sin(a4)],             [0,0]        ]);     } } pie_slice(50, 40, 120); It works by covering the wanted bit of the circle with a fan of triangles, each 1/4 of the angle. That means the angle is no more than a right angle so the triangle edge boundary is made outside the circle by increasing the radius by sqrt(2) On 21 August 2012 15:36, Alan Cox wrote: On Tue, 21 Aug 2012 16:05:05 +0200 Peter Uithoven <[hidden email]> wrote: > Hi OpenSCAD people, > > I work a lot in 2D and I really mis a way to create a way to create a pie > (pizza slice) shape. > > A workaround for me is the following function in which I create a circle > and then remove parts of it with rectangles, but this is limited to whole > quarters. Why not just remove a triangle from it ? Alan _______________________________________________ OpenSCAD mailing list [hidden email] http://rocklinux.net/mailman/listinfo/openscad http://openscad.org - https://flattr.com/thing/121566
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)

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)

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)

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)

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)

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. In reply to this post by clothbot Sorry if this is a question with a really obvious answer, but what determines the thickness of the slice in the following code: module pie_slice(r=3.0,a=30) {   \$fn=64;   intersection() {     circle(r=r);     square(r);     rotate(a-90) square(r);   } } pie_slice(r=10,a=15);
Open this post in threaded view
|

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

 Administrator Hi jon, a. your reply has not made it to the mailing list yet as it is still flagged "This post has NOT been accepted by the mailing list yet", you need to complete registrationb. The pie_slice() is a 2D object (uses square/circle), to give it thickness you need to use linear_extrude() See http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/2D_to_3D_Extrusion#Linear_Extrude Admin - email* me if you need anything, or if I've done something stupid... * click on my MichaelAtOz label, there is a link to email me. 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!
Open this post in threaded view
|

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

 This post was updated on . Here is a way to make a pie also module pie(radius=90, angle=45) {   // Create a pie slice, from [0..360]          bigger = radius * 3;          partial = angle / 12;         intersection()         {                 polygon ( points= [ [0,0],                                             [bigger, 0],                                             [ bigger * cos(partial * 1), bigger * sin(partial * 1)],                                             [ bigger * cos(partial * 2), bigger * sin(partial * 2)],                                             [ bigger * cos(partial * 3), bigger * sin(partial * 3)],                                             [ bigger * cos(partial * 4), bigger * sin(partial * 4)],                                             [ bigger * cos(partial * 5), bigger * sin(partial * 5)],                                             [ bigger * cos(partial * 6), bigger * sin(partial * 6)],                                             [ bigger * cos(partial * 7), bigger * sin(partial * 7)],                                             [ bigger * cos(partial * 8), bigger * sin(partial * 8)],                                             [ bigger * cos(partial * 9), bigger * sin(partial * 9)],                                             [ bigger * cos(partial * 10), bigger * sin(partial * 10)],                                             [ bigger * cos(partial * 11), bigger * sin(partial * 11)],                                             [ bigger * cos(partial * 12), bigger * sin(partial * 12)]                                         ]) ;                 circle (radius);         } } pie (radius = 30, angle = 200);