Discussion:
[OpenSCAD] Creating pie (pizza slice) shape (need a dynamic length array)
Peter Uithoven
2012-08-21 14:05:05 UTC
Permalink
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
Andrew Plumb
2012-08-21 14:13:25 UTC
Permalink
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.
Post by Peter Uithoven
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
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
--

"The future is already here. It's just not very evenly distributed" -- William Gibson

Me: http://clothbot.com/wiki/
MichaelAtOz
2014-02-26 00:03:03 UTC
Permalink
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 registration
<http://forum.openscad.org/mailing_list/MailingListOptions.jtp?forum=1>

b. 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



--
View this message in context: http://forum.openscad.org/Creating-pie-pizza-slice-shape-need-a-dynamic-length-array-tp3148p7008.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
shadowwynd
2014-03-01 13:13:19 UTC
Permalink
Here's a simple 90 degree or less slice:

module pie_90(radius=90, angle=45)
{
// Create a pie slice up to 90°

bigger = radius * 3;

intersection()
{
polygon ( points= [ [0,0], [bigger, 0], [ bigger * cos(angle), bigger *
sin(angle)] ]) ;
circle (radius);
}

}

pie_90 (radius = 10, angle = 85);




--
View this message in context: http://forum.openscad.org/Creating-pie-pizza-slice-shape-need-a-dynamic-length-array-tp3148p7050.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
DarioPellegrini
2018-09-15 17:18:21 UTC
Permalink
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/
Ian Shumsky
2012-08-21 14:24:48 UTC
Permalink
Post by Peter Uithoven
A workaround for me is the following function in which I create a circle
and
Post by Peter Uithoven
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
Alan Cox
2012-08-21 14:36:57 UTC
Permalink
On Tue, 21 Aug 2012 16:05:05 +0200
Post by Peter Uithoven
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
nop head
2012-08-21 15:55:48 UTC
Permalink
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)
Post by Alan Cox
On Tue, 21 Aug 2012 16:05:05 +0200
Post by Peter Uithoven
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
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
nop head
2012-08-21 16:31:55 UTC
Permalink
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);
Post by nop head
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)
Post by Alan Cox
On Tue, 21 Aug 2012 16:05:05 +0200
Post by Peter Uithoven
Hi OpenSCAD people,
I work a lot in 2D and I really mis a way to create a way to create a
pie
Post by Peter Uithoven
(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
Post by Peter Uithoven
quarters.
Why not just remove a triangle from it ?
Alan
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Kevin Crowley
2012-08-21 16:59:27 UTC
Permalink
I made a small change so that it would do the slice in 1 degree sections
regardless of size.


module point(x,y) translate([x,y]) circle(0.01);



module pie_slice(r, a0, a1) {


$fa = 5;

R = r * 1.02;

intersection() {

circle(r);

hull() {

point(0,0);

for(i = [0:(a0-a1)])

assign(a = ((4 - i) * a0 + i * a1) /(a0-a1))

point(R * cos(a), R * sin(a));

}

}

}


pie_slice(50, 120,90);
Post by nop head
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);
Post by nop head
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)
Post by Alan Cox
On Tue, 21 Aug 2012 16:05:05 +0200
Post by Peter Uithoven
Hi OpenSCAD people,
I work a lot in 2D and I really mis a way to create a way to create a
pie
Post by Peter Uithoven
(pizza slice) shape.
A workaround for me is the following function in which I create a
circle
Post by Peter Uithoven
and then remove parts of it with rectangles, but this is limited to
whole
Post by Peter Uithoven
quarters.
Why not just remove a triangle from it ?
Alan
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
nop head
2012-08-21 17:07:11 UTC
Permalink
What is the benefit? The circumference of the circle is defined by the $fa,
not the number of triangle it is intersected with. Doesn't this just slow
it down?
Post by Kevin Crowley
I made a small change so that it would do the slice in 1 degree sections
regardless of size.
module point(x,y) translate([x,y]) circle(0.01);
module pie_slice(r, a0, a1) {
$fa = 5;
R = r * 1.02;
intersection() {
circle(r);
hull() {
point(0,0);
for(i = [0:(a0-a1)])
assign(a = ((4 - i) * a0 + i * a1) /(a0-a1))
point(R * cos(a), R * sin(a));
}
}
}
pie_slice(50, 120,90);
Post by nop head
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);
Post by nop head
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)
Post by Alan Cox
On Tue, 21 Aug 2012 16:05:05 +0200
Post by Peter Uithoven
Hi OpenSCAD people,
I work a lot in 2D and I really mis a way to create a way to create a
pie
Post by Peter Uithoven
(pizza slice) shape.
A workaround for me is the following function in which I create a
circle
Post by Peter Uithoven
and then remove parts of it with rectangles, but this is limited to
whole
Post by Peter Uithoven
quarters.
Why not just remove a triangle from it ?
Alan
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Peter Uithoven
2012-08-21 17:22:43 UTC
Permalink
I adjusted an earlier script so that you can do ellipses as well

$fn = 30;
module pie_slice(size, start_angle, end_angle)
{
rx = ((len(size) > 1)? size[0] : size);
ry = ((len(size) > 1)? size[1] : size);
trx = rx* sqrt(2) + 1;
try = ry* 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() {
if(len(size) > 1)
ellipse(rx*2,ry*2);
else
circle(rx);
polygon([
[0,0],
[trx * cos(a0), try * sin(a0)],
[trx * cos(a1), try * sin(a1)],
[trx * cos(a2), try * sin(a2)],
[trx * cos(a3), try * sin(a3)],
[trx * cos(a4), try * sin(a4)],
[0,0]
]);
}
}
#pie_slice(50, 0, 135);
pie_slice([100,50], 0, 135);
module ellipse(width, height) {
scale([1, height/width, 1]) circle(r=width/2);
}
What is the benefit? The circumference of the circle is defined by the
$fa, not the number of triangle it is intersected with. Doesn't this just
slow it down?
Post by Kevin Crowley
I made a small change so that it would do the slice in 1 degree sections
regardless of size.
module point(x,y) translate([x,y]) circle(0.01);
module pie_slice(r, a0, a1) {
$fa = 5;
R = r * 1.02;
intersection() {
circle(r);
hull() {
point(0,0);
for(i = [0:(a0-a1)])
assign(a = ((4 - i) * a0 + i * a1) /(a0-a1))
point(R * cos(a), R * sin(a));
}
}
}
pie_slice(50, 120,90);
Post by nop head
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);
Post by nop head
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)
Post by Alan Cox
On Tue, 21 Aug 2012 16:05:05 +0200
Post by Peter Uithoven
Hi OpenSCAD people,
I work a lot in 2D and I really mis a way to create a way to create
a pie
Post by Peter Uithoven
(pizza slice) shape.
A workaround for me is the following function in which I create a
circle
Post by Peter Uithoven
and then remove parts of it with rectangles, but this is limited to
whole
Post by Peter Uithoven
quarters.
Why not just remove a triangle from it ?
Alan
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Kevin Crowley
2012-08-21 17:39:49 UTC
Permalink
It does take more time and that is a drawback but what I was working
toward without realizing it is that part of your code would let you make
slices of pie independent of any circle.

module point(x,y) translate([x,y]) circle(0.01);


module pie_slice(R, a0, a1) {

$fa = 5;

if(a0>a1){

hull() {

point(0,0);

for(i = [0:(a0-a1)])

assign(a = ((4 - i) * a0 + i * a1) /(a0-a1))

point(R * cos(a), R * sin(a));

}

}

}


pie_slice(50, 120,90);
Post by nop head
What is the benefit? The circumference of the circle is defined by the
$fa, not the number of triangle it is intersected with. Doesn't this just
slow it down?
Post by Kevin Crowley
I made a small change so that it would do the slice in 1 degree sections
regardless of size.
module point(x,y) translate([x,y]) circle(0.01);
module pie_slice(r, a0, a1) {
$fa = 5;
R = r * 1.02;
intersection() {
circle(r);
hull() {
point(0,0);
for(i = [0:(a0-a1)])
assign(a = ((4 - i) * a0 + i * a1) /(a0-a1))
point(R * cos(a), R * sin(a));
}
}
}
pie_slice(50, 120,90);
Post by nop head
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);
Post by nop head
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)
Post by Alan Cox
On Tue, 21 Aug 2012 16:05:05 +0200
Post by Peter Uithoven
Hi OpenSCAD people,
I work a lot in 2D and I really mis a way to create a way to create
a pie
Post by Peter Uithoven
(pizza slice) shape.
A workaround for me is the following function in which I create a
circle
Post by Peter Uithoven
and then remove parts of it with rectangles, but this is limited to
whole
Post by Peter Uithoven
quarters.
Why not just remove a triangle from it ?
Alan
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
nop head
2012-08-21 17:53:58 UTC
Permalink
Yes hull() allows computed geometry without needing dynamic arrays, but
only when convex.
Post by Kevin Crowley
It does take more time and that is a drawback but what I was working
toward without realizing it is that part of your code would let you make
slices of pie independent of any circle.
module point(x,y) translate([x,y]) circle(0.01);
module pie_slice(R, a0, a1) {
$fa = 5;
if(a0>a1){
hull() {
point(0,0);
for(i = [0:(a0-a1)])
assign(a = ((4 - i) * a0 + i * a1) /(a0-a1))
point(R * cos(a), R * sin(a));
}
}
}
pie_slice(50, 120,90);
Post by nop head
What is the benefit? The circumference of the circle is defined by the
$fa, not the number of triangle it is intersected with. Doesn't this just
slow it down?
Post by Kevin Crowley
I made a small change so that it would do the slice in 1 degree
sections regardless of size.
module point(x,y) translate([x,y]) circle(0.01);
module pie_slice(r, a0, a1) {
$fa = 5;
R = r * 1.02;
intersection() {
circle(r);
hull() {
point(0,0);
for(i = [0:(a0-a1)])
assign(a = ((4 - i) * a0 + i * a1) /(a0-a1))
point(R * cos(a), R * sin(a));
}
}
}
pie_slice(50, 120,90);
Post by nop head
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);
Post by nop head
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)
Post by Alan Cox
On Tue, 21 Aug 2012 16:05:05 +0200
Post by Peter Uithoven
Hi OpenSCAD people,
I work a lot in 2D and I really mis a way to create a way to create
a pie
Post by Peter Uithoven
(pizza slice) shape.
A workaround for me is the following function in which I create a
circle
Post by Peter Uithoven
and then remove parts of it with rectangles, but this is limited to
whole
Post by Peter Uithoven
quarters.
Why not just remove a triangle from it ?
Alan
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Kevin Crowley
2012-08-21 19:12:53 UTC
Permalink
This yields just an arc segment which is both vex and cave.

module point(x,y) translate([x,y]) circle(0.01);


module pie_slice(R, a0, a1) {

$fa = 5;

if(a0>a1){

hull() {

point(0,0);

for(i = [0:(a0-a1)])

assign(a = ((4 - i) * a0 + i * a1) /(a0-a1))

point(R * cos(a), R * sin(a));

}

}

}


difference(){

pie_slice(50, 120,90);

circle(49);

}
Post by nop head
Yes hull() allows computed geometry without needing dynamic arrays, but
only when convex.
Post by Kevin Crowley
It does take more time and that is a drawback but what I was working
toward without realizing it is that part of your code would let you make
slices of pie independent of any circle.
module point(x,y) translate([x,y]) circle(0.01);
module pie_slice(R, a0, a1) {
$fa = 5;
if(a0>a1){
hull() {
point(0,0);
for(i = [0:(a0-a1)])
assign(a = ((4 - i) * a0 + i * a1) /(a0-a1))
point(R * cos(a), R * sin(a));
}
}
}
pie_slice(50, 120,90);
Post by nop head
What is the benefit? The circumference of the circle is defined by the
$fa, not the number of triangle it is intersected with. Doesn't this just
slow it down?
Post by Kevin Crowley
I made a small change so that it would do the slice in 1 degree
sections regardless of size.
module point(x,y) translate([x,y]) circle(0.01);
module pie_slice(r, a0, a1) {
$fa = 5;
R = r * 1.02;
intersection() {
circle(r);
hull() {
point(0,0);
for(i = [0:(a0-a1)])
assign(a = ((4 - i) * a0 + i * a1) /(a0-a1))
point(R * cos(a), R * sin(a));
}
}
}
pie_slice(50, 120,90);
Post by nop head
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);
Post by nop head
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)
Post by Alan Cox
On Tue, 21 Aug 2012 16:05:05 +0200
Post by Peter Uithoven
Hi OpenSCAD people,
I work a lot in 2D and I really mis a way to create a way to
create a pie
Post by Peter Uithoven
(pizza slice) shape.
A workaround for me is the following function in which I create a
circle
Post by Peter Uithoven
and then remove parts of it with rectangles, but this is limited
to whole
Post by Peter Uithoven
quarters.
Why not just remove a triangle from it ?
Alan
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Peter Uithoven
2012-08-21 23:20:09 UTC
Permalink
My OpenSCAD doesn't seem to recognise point, is this added in a dev
version?

Best regards,
Peter Uithoven
Post by Kevin Crowley
This yields just an arc segment which is both vex and cave.
module point(x,y) translate([x,y]) circle(0.01);
module pie_slice(R, a0, a1) {
$fa = 5;
if(a0>a1){
hull() {
point(0,0);
for(i = [0:(a0-a1)])
assign(a = ((4 - i) * a0 + i * a1) /(a0-a1))
point(R * cos(a), R * sin(a));
}
}
}
difference(){
pie_slice(50, 120,90);
circle(49);
}
Post by nop head
Yes hull() allows computed geometry without needing dynamic arrays, but
only when convex.
Post by Kevin Crowley
It does take more time and that is a drawback but what I was working
toward without realizing it is that part of your code would let you make
slices of pie independent of any circle.
module point(x,y) translate([x,y]) circle(0.01);
module pie_slice(R, a0, a1) {
$fa = 5;
if(a0>a1){
hull() {
point(0,0);
for(i = [0:(a0-a1)])
assign(a = ((4 - i) * a0 + i * a1) /(a0-a1))
point(R * cos(a), R * sin(a));
}
}
}
pie_slice(50, 120,90);
Post by nop head
What is the benefit? The circumference of the circle is defined by the
$fa, not the number of triangle it is intersected with. Doesn't this just
slow it down?
Post by Kevin Crowley
I made a small change so that it would do the slice in 1 degree
sections regardless of size.
module point(x,y) translate([x,y]) circle(0.01);
module pie_slice(r, a0, a1) {
$fa = 5;
R = r * 1.02;
intersection() {
circle(r);
hull() {
point(0,0);
for(i = [0:(a0-a1)])
assign(a = ((4 - i) * a0 + i * a1) /(a0-a1))
point(R * cos(a), R * sin(a));
}
}
}
pie_slice(50, 120,90);
Post by nop head
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);
Post by nop head
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)
Post by Alan Cox
On Tue, 21 Aug 2012 16:05:05 +0200
Post by Peter Uithoven
Hi OpenSCAD people,
I work a lot in 2D and I really mis a way to create a way to
create a pie
Post by Peter Uithoven
(pizza slice) shape.
A workaround for me is the following function in which I create a
circle
Post by Peter Uithoven
and then remove parts of it with rectangles, but this is limited
to whole
Post by Peter Uithoven
quarters.
Why not just remove a triangle from it ?
Alan
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
nop head
2012-08-22 00:05:49 UTC
Permalink
No it the first line of the script: module point(x,y) translate([x,y])
circle(0.01);

It is my approximation to a point. If openscad had one it would be useful.
Also an operation like hull that would take a set of child points and make
then into a polygon would then allow concave polygons with a run time
computed number of vertices to be generated and presumably would be a lot
faster than hull, which is overkill for making simple polygons and can only
make convex shapes.
Post by Peter Uithoven
My OpenSCAD doesn't seem to recognise point, is this added in a dev
version?
Best regards,
Peter Uithoven
Post by Kevin Crowley
This yields just an arc segment which is both vex and cave.
module point(x,y) translate([x,y]) circle(0.01);
module pie_slice(R, a0, a1) {
$fa = 5;
if(a0>a1){
hull() {
point(0,0);
for(i = [0:(a0-a1)])
assign(a = ((4 - i) * a0 + i * a1) /(a0-a1))
point(R * cos(a), R * sin(a));
}
}
}
difference(){
pie_slice(50, 120,90);
circle(49);
}
Post by nop head
Yes hull() allows computed geometry without needing dynamic arrays, but
only when convex.
Post by Kevin Crowley
It does take more time and that is a drawback but what I was working
toward without realizing it is that part of your code would let you make
slices of pie independent of any circle.
module point(x,y) translate([x,y]) circle(0.01);
module pie_slice(R, a0, a1) {
$fa = 5;
if(a0>a1){
hull() {
point(0,0);
for(i = [0:(a0-a1)])
assign(a = ((4 - i) * a0 + i * a1) /(a0-a1))
point(R * cos(a), R * sin(a));
}
}
}
pie_slice(50, 120,90);
Post by nop head
What is the benefit? The circumference of the circle is defined by the
$fa, not the number of triangle it is intersected with. Doesn't this just
slow it down?
Post by Kevin Crowley
I made a small change so that it would do the slice in 1 degree
sections regardless of size.
module point(x,y) translate([x,y]) circle(0.01);
module pie_slice(r, a0, a1) {
$fa = 5;
R = r * 1.02;
intersection() {
circle(r);
hull() {
point(0,0);
for(i = [0:(a0-a1)])
assign(a = ((4 - i) * a0 + i * a1) /(a0-a1))
point(R * cos(a), R * sin(a));
}
}
}
pie_slice(50, 120,90);
Post by nop head
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);
Post by nop head
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)
Post by Alan Cox
On Tue, 21 Aug 2012 16:05:05 +0200
Post by Peter Uithoven
Hi OpenSCAD people,
I work a lot in 2D and I really mis a way to create a way to
create a pie
Post by Peter Uithoven
(pizza slice) shape.
A workaround for me is the following function in which I create
a circle
Post by Peter Uithoven
and then remove parts of it with rectangles, but this is limited
to whole
Post by Peter Uithoven
quarters.
Why not just remove a triangle from it ?
Alan
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
Giles Bathgate
2012-08-22 04:46:52 UTC
Permalink
Technically openscad (cgal) will create a point when you intersect the
corners of two cubes:

module point(){
intersection(){
cube([1,1,1]);
translate([-1,-1,-1])cube([1,1,1]);
}
}

Two problems with this though.

1) its not visible in openscad even when show edges is enabled
2) it crashes when used within a hull operation

The point is there though, I tested this with rapcad, and it creates a
visible point with show edges enabled, however it also crashes rapcad
when used in a hull operation ;)

Regards

Giles
Post by nop head
No it the first line of the script: module point(x,y) translate([x,y])
circle(0.01);
It is my approximation to a point. If openscad had one it would be useful.
Also an operation like hull that would take a set of child points and make
then into a polygon would then allow concave polygons with a run time
computed number of vertices to be generated and presumably would be a lot
faster than hull, which is overkill for making simple polygons and can only
make convex shapes.
Post by Peter Uithoven
My OpenSCAD doesn't seem to recognise point, is this added in a dev
version?
Best regards,
Peter Uithoven
Post by Kevin Crowley
This yields just an arc segment which is both vex and cave.
module point(x,y) translate([x,y]) circle(0.01);
module pie_slice(R, a0, a1) {
$fa = 5;
if(a0>a1){
hull() {
point(0,0);
for(i = [0:(a0-a1)])
assign(a = ((4 - i) * a0 + i * a1) /(a0-a1))
point(R * cos(a), R * sin(a));
}
}
}
difference(){
pie_slice(50, 120,90);
circle(49);
}
Post by nop head
Yes hull() allows computed geometry without needing dynamic arrays, but
only when convex.
Post by Kevin Crowley
It does take more time and that is a drawback but what I was working
toward without realizing it is that part of your code would let you make
slices of pie independent of any circle.
module point(x,y) translate([x,y]) circle(0.01);
module pie_slice(R, a0, a1) {
$fa = 5;
if(a0>a1){
hull() {
point(0,0);
for(i = [0:(a0-a1)])
assign(a = ((4 - i) * a0 + i * a1) /(a0-a1))
point(R * cos(a), R * sin(a));
}
}
}
pie_slice(50, 120,90);
Post by nop head
What is the benefit? The circumference of the circle is defined by the
$fa, not the number of triangle it is intersected with. Doesn't this just
slow it down?
Post by Kevin Crowley
I made a small change so that it would do the slice in 1 degree
sections regardless of size.
module point(x,y) translate([x,y]) circle(0.01);
module pie_slice(r, a0, a1) {
$fa = 5;
R = r * 1.02;
intersection() {
circle(r);
hull() {
point(0,0);
for(i = [0:(a0-a1)])
assign(a = ((4 - i) * a0 + i * a1) /(a0-a1))
point(R * cos(a), R * sin(a));
}
}
}
pie_slice(50, 120,90);
Post by nop head
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);
Post by nop head
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)
Post by Alan Cox
On Tue, 21 Aug 2012 16:05:05 +0200
Post by Peter Uithoven
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
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
whosawhatsis
2012-08-22 05:10:23 UTC
Permalink
All of these solutions seem overcomplicated or imprecise, so I felt compelled to post mine. Btw, the second line makes this work for all angles, not just those in the range of 0-360 degrees (not sure that a few of the others work outside that range).

module slice(r = 10, deg = 30) {
degn = (deg % 360 > 0) ? deg % 360 : deg % 360 + 360;
difference() {
circle(r);
if (degn > 180) intersection_for(a = [0, 180 - degn]) rotate(a) translate([-r, 0, 0]) square(r * 2);
else union() for(a = [0, 180 - degn]) rotate(a) translate([-r, 0, 0]) square(r * 2);
}
}

slice(10, 135);
Post by Giles Bathgate
Technically openscad (cgal) will create a point when you intersect the
module point(){
intersection(){
cube([1,1,1]);
translate([-1,-1,-1])cube([1,1,1]);
}
}
Two problems with this though.
1) its not visible in openscad even when show edges is enabled
2) it crashes when used within a hull operation
The point is there though, I tested this with rapcad, and it creates a
visible point with show edges enabled, however it also crashes rapcad
when used in a hull operation ;)
Regards
Giles
No it the first line of the script: module point(x,y) translate([x,y])
circle(0.01);
It is my approximation to a point. If openscad had one it would be useful.
Also an operation like hull that would take a set of child points and make
then into a polygon would then allow concave polygons with a run time
computed number of vertices to be generated and presumably would be a lot
faster than hull, which is overkill for making simple polygons and can only
make convex shapes.
Post by Peter Uithoven
My OpenSCAD doesn't seem to recognise point, is this added in a dev
version?
Best regards,
Peter Uithoven
Post by Kevin Crowley
This yields just an arc segment which is both vex and cave.
module point(x,y) translate([x,y]) circle(0.01);
module pie_slice(R, a0, a1) {
$fa = 5;
if(a0>a1){
hull() {
point(0,0);
for(i = [0:(a0-a1)])
assign(a = ((4 - i) * a0 + i * a1) /(a0-a1))
point(R * cos(a), R * sin(a));
}
}
}
difference(){
pie_slice(50, 120,90);
circle(49);
}
Post by nop head
Yes hull() allows computed geometry without needing dynamic arrays, but
only when convex.
It does take more time and that is a drawback but what I was working
toward without realizing it is that part of your code would let you make
slices of pie independent of any circle.
module point(x,y) translate([x,y]) circle(0.01);
module pie_slice(R, a0, a1) {
$fa = 5;
if(a0>a1){
hull() {
point(0,0);
for(i = [0:(a0-a1)])
assign(a = ((4 - i) * a0 + i * a1) /(a0-a1))
point(R * cos(a), R * sin(a));
}
}
}
pie_slice(50, 120,90);
Post by nop head
What is the benefit? The circumference of the circle is defined by the
$fa, not the number of triangle it is intersected with. Doesn't this just
slow it down?
I made a small change so that it would do the slice in 1 degree
sections regardless of size.
module point(x,y) translate([x,y]) circle(0.01);
module pie_slice(r, a0, a1) {
$fa = 5;
R = r * 1.02;
intersection() {
circle(r);
hull() {
point(0,0);
for(i = [0:(a0-a1)])
assign(a = ((4 - i) * a0 + i * a1) /(a0-a1))
point(R * cos(a), R * sin(a));
}
}
}
pie_slice(50, 120,90);
Post by nop head
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);
Post by nop head
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)
Post by Alan Cox
On Tue, 21 Aug 2012 16:05:05 +0200
Post by Peter Uithoven
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
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
_______________________________________________
OpenSCAD mailing list
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566
QuackingPlums
2014-09-30 11:05:14 UTC
Permalink
I spotted some weirdness with nophead's first generic solution to the pie
slice when using it together with minkowski() to make a rounded slice - it
only works for certain values of r:

minkowski()
{
Slice(45, 0, 60); // doesn't work
//Slice(46, 0, 60); // does work
circle(r = 3);
}

module 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]
]);
}
}

Can anyone explain why? There are no errors in the output window.

The problem doesn't manifest (for these values of r anyway!) in the concise
version, or whosawhatsis version.

PS - is there a better way of quoting code in this mailing list?



--
View this message in context: http://forum.openscad.org/Creating-pie-pizza-slice-shape-need-a-dynamic-length-array-tp3148p9803.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Marius Kintel
2014-09-30 16:44:20 UTC
Permalink
Post by QuackingPlums
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
Parkinbot
2018-09-15 21:06:27 UTC
Permalink
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/
runsun
2018-09-16 05:09:48 UTC
Permalink
Add my version for completeness. It's part of my lib so I'll only post the
function signature here
'cos the lib needs to be downloaded anyway.

It takes a different approach, requiring any 3 points (PQR) in the 3D space.

function arcPts(
pqr
, n=6 // # of points produced
, rad= undef // radius, default = dPQ
, a = undef // angle, default = aPQR
, a2 = undef // a 2nd angle, if given, start from a pt
defined by a and rad
// , then move upward away from plane
PQR
, ratio= 1 // If given, replace rad.
)

See the following pic for demo, which is generated with this code
<https://bitbucket.org/runsun/scadx/src/master/demos/demo_arcPts.scad> .
<Loading Image...>










-----

$ Runsun Pan, PhD $ libs: scadx , doctest , faces ( git ), offline doc ( git ), runscad.py ( 2 , git ), editor of choice: CudaText ( OpenSCAD lexer );&nbsp;$ Tips ;&nbsp;$ Snippets

--
Sent from: http://forum.openscad.org/
TLC123
2018-09-16 15:38:53 UTC
Permalink
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/
Torsten Paul
2018-09-16 15:45:02 UTC
Permalink
Post by nop head
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.
TLC123
2018-09-16 16:34:11 UTC
Permalink
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/

Loading...