I adjusted an earlier script so that you can do ellipses as well
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 CrowleyI 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 headA 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 headmodule 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 CoxOn Tue, 21 Aug 2012 16:05:05 +0200
Post by Peter UithovenHi 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 Uithovenand then remove parts of it with rectangles, but this is limited to
whole
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