discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Cutting a pie slice

SP
Sanjeev Prabhakar
Fri, Oct 14, 2022 5:17 AM

I think Mr.Jordan's solution is the most simple and best in this case .

On Fri, 14 Oct, 2022, 9:44 am Jordan Brown, openscad@jordan.maileater.net
wrote:

Here's another simple answer.

module pie(a) {
polygon([
[0,0],
for (i=[0:a]) [cos(i), sin(i)]
]);
}

pie(360*$t);

Left for the reader:

- Extending to larger than unit.
- Extending to 3D.
- Handling a=0.
- Handling a=360.

OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

I think Mr.Jordan's solution is the most simple and best in this case . On Fri, 14 Oct, 2022, 9:44 am Jordan Brown, <openscad@jordan.maileater.net> wrote: > Here's another simple answer. > > module pie(a) { > polygon([ > [0,0], > for (i=[0:a]) [cos(i), sin(i)] > ]); > } > > pie(360*$t); > > Left for the reader: > > - Extending to larger than unit. > - Extending to 3D. > - Handling a=0. > - Handling a=360. > > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
JB
Jordan Brown
Fri, Oct 14, 2022 5:26 AM

On 10/13/2022 10:17 PM, Sanjeev Prabhakar wrote:

I think Mr.Jordan's solution is the most simple and best in this case .

While I appreciate the hat-tip, no, Whosawhatsis's is better for the 3D
case that I think he really wanted.

$fn=50;
module pie(a) {
    rotate_extrude(angle=a) square();
}
pie(360*$t);

Note that the "active ingredient" is just one line.

On 10/13/2022 10:17 PM, Sanjeev Prabhakar wrote: > I think Mr.Jordan's solution is the most simple and best in this case . While I appreciate the hat-tip, no, Whosawhatsis's is better for the 3D case that I think he really wanted. $fn=50; module pie(a) { rotate_extrude(angle=a) square(); } pie(360*$t); Note that the "active ingredient" is just one line.
SP
Sanjeev Prabhakar
Fri, Oct 14, 2022 6:10 AM

Yes
In case the shape is not a cylinder, then probably a few more lines to be
written and difference( ) command would be required here.

On Fri, 14 Oct, 2022, 10:56 am Jordan Brown, openscad@jordan.maileater.net
wrote:

On 10/13/2022 10:17 PM, Sanjeev Prabhakar wrote:

I think Mr.Jordan's solution is the most simple and best in this case .

While I appreciate the hat-tip, no, Whosawhatsis's is better for the 3D
case that I think he really wanted.

$fn=50;
module pie(a) {
rotate_extrude(angle=a) square();
}
pie(360*$t);

Note that the "active ingredient" is just one line.

Yes In case the shape is not a cylinder, then probably a few more lines to be written and difference( ) command would be required here. On Fri, 14 Oct, 2022, 10:56 am Jordan Brown, <openscad@jordan.maileater.net> wrote: > On 10/13/2022 10:17 PM, Sanjeev Prabhakar wrote: > > I think Mr.Jordan's solution is the most simple and best in this case . > > > While I appreciate the hat-tip, no, Whosawhatsis's is better for the 3D > case that I think he really wanted. > > $fn=50; > module pie(a) { > rotate_extrude(angle=a) square(); > } > pie(360*$t); > > Note that the "active ingredient" is just one line. > >
JB
Jordan Brown
Fri, Oct 14, 2022 6:35 AM

Here's yet another answer:  build the polyhedron on your own.

module pie(a) {
    // Approximately one side per degree.
    n = ceil(a);
    // Return indexes into the point list for the specified
    // index into the bottom or top.
    function bottom(i) = 2+i;
    function top(i) = 2+n+1+i;
    if (a > 0) {
        points = [
            [0,0,0],
            [0,0,1],
            for (z=[0,1], i=[0:n]) [cos(i/n*a), sin(i/n*a), z]
        ];

        faces = [
            // Bottom
            for (i=[0:n-1]) [0, bottom(i), bottom(i+1)],
            // Top
            for (i=[0:n-1]) [1, top(i+1), top(i)],
            // Triangles pointing up
            for (i=[0:n-1]) [bottom(i+1), bottom(i), top(i)],
            // Triangles pointing down
            for (i=[0:n-1]) [top(i), top(i+1), bottom(i+1)],
            // Sides
            [ 0, top(0), bottom(0) ],
            [ 0, 1, top(0) ],
            [ 0, bottom(n), 1],
            [ 1, bottom(n), top(n)],
        ];
        polyhedron(points=points, faces=faces);
    }
}

pie($t*360);

This answer is, of course, enormously more complex than any of the
others.  However, learning the techniques involved in algorithmically
building polyhedra will let you do lots of interesting things - and
generally the performance is excellent.

Here's yet another answer:  build the polyhedron on your own. module pie(a) { // Approximately one side per degree. n = ceil(a); // Return indexes into the point list for the specified // index into the bottom or top. function bottom(i) = 2+i; function top(i) = 2+n+1+i; if (a > 0) { points = [ [0,0,0], [0,0,1], for (z=[0,1], i=[0:n]) [cos(i/n*a), sin(i/n*a), z] ]; faces = [ // Bottom for (i=[0:n-1]) [0, bottom(i), bottom(i+1)], // Top for (i=[0:n-1]) [1, top(i+1), top(i)], // Triangles pointing up for (i=[0:n-1]) [bottom(i+1), bottom(i), top(i)], // Triangles pointing down for (i=[0:n-1]) [top(i), top(i+1), bottom(i+1)], // Sides [ 0, top(0), bottom(0) ], [ 0, 1, top(0) ], [ 0, bottom(n), 1], [ 1, bottom(n), top(n)], ]; polyhedron(points=points, faces=faces); } } pie($t*360); This answer is, of course, enormously more complex than any of the others.  However, learning the techniques involved in algorithmically building polyhedra will let you do lots of interesting things - and generally the performance is excellent.
NH
nop head
Fri, Oct 14, 2022 8:20 AM

My version is just an intersection between a circle and a four triangle fan.

//
//! A sector of a circle between two angles.
//
include <../utils/core/core.scad>

module sector(r, start_angle, end_angle) { //! Create specified sector
given radius r, start_angle and end_angle
R = r * sqrt(2) + 1;

if(end_angle > start_angle)
    intersection() {
        circle4n(r);

        // A 4 triangle fan
        polygon([[0, 0],
                 for(i = [0 : 4], a = start_angle + i * (end_angle -

start_angle) / 4) R * [cos(a), sin(a)] ]);
}
}

On Fri, 14 Oct 2022 at 07:35, Jordan Brown openscad@jordan.maileater.net
wrote:

Here's yet another answer:  build the polyhedron on your own.

module pie(a) {
// Approximately one side per degree.
n = ceil(a);
// Return indexes into the point list for the specified
// index into the bottom or top.
function bottom(i) = 2+i;
function top(i) = 2+n+1+i;
if (a > 0) {
points = [
[0,0,0],
[0,0,1],
for (z=[0,1], i=[0:n]) [cos(i/na), sin(i/na), z]
];

     faces = [
         // Bottom
         for (i=[0:n-1]) [0, bottom(i), bottom(i+1)],
         // Top
         for (i=[0:n-1]) [1, top(i+1), top(i)],
         // Triangles pointing up
         for (i=[0:n-1]) [bottom(i+1), bottom(i), top(i)],
         // Triangles pointing down
         for (i=[0:n-1]) [top(i), top(i+1), bottom(i+1)],
         // Sides
         [ 0, top(0), bottom(0) ],
         [ 0, 1, top(0) ],
         [ 0, bottom(n), 1],
         [ 1, bottom(n), top(n)],
     ];
     polyhedron(points=points, faces=faces);
 }

}

pie($t*360);

This answer is, of course, enormously more complex than any of the
others.  However, learning the techniques involved in algorithmically
building polyhedra will let you do lots of interesting things - and
generally the performance is excellent.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

My version is just an intersection between a circle and a four triangle fan. // //! A sector of a circle between two angles. // include <../utils/core/core.scad> module sector(r, start_angle, end_angle) { //! Create specified sector given radius `r`, `start_angle` and `end_angle` R = r * sqrt(2) + 1; if(end_angle > start_angle) intersection() { circle4n(r); // A 4 triangle fan polygon([[0, 0], for(i = [0 : 4], a = start_angle + i * (end_angle - start_angle) / 4) R * [cos(a), sin(a)] ]); } } On Fri, 14 Oct 2022 at 07:35, Jordan Brown <openscad@jordan.maileater.net> wrote: > Here's yet another answer: build the polyhedron on your own. > > module pie(a) { > // Approximately one side per degree. > n = ceil(a); > // Return indexes into the point list for the specified > // index into the bottom or top. > function bottom(i) = 2+i; > function top(i) = 2+n+1+i; > if (a > 0) { > points = [ > [0,0,0], > [0,0,1], > for (z=[0,1], i=[0:n]) [cos(i/n*a), sin(i/n*a), z] > ]; > > faces = [ > // Bottom > for (i=[0:n-1]) [0, bottom(i), bottom(i+1)], > // Top > for (i=[0:n-1]) [1, top(i+1), top(i)], > // Triangles pointing up > for (i=[0:n-1]) [bottom(i+1), bottom(i), top(i)], > // Triangles pointing down > for (i=[0:n-1]) [top(i), top(i+1), bottom(i+1)], > // Sides > [ 0, top(0), bottom(0) ], > [ 0, 1, top(0) ], > [ 0, bottom(n), 1], > [ 1, bottom(n), top(n)], > ]; > polyhedron(points=points, faces=faces); > } > } > > pie($t*360); > > This answer is, of course, enormously more complex than any of the > others. However, learning the techniques involved in algorithmically > building polyhedra will let you do lots of interesting things - and > generally the performance is excellent. > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >
DM
Douglas Miller
Fri, Oct 14, 2022 5:37 PM

This is simpler, and renders much faster:

h=50;
d=300;
a=34;

rotate_extrude(angle = 360-a) square([d/2,h]);

// if you want the slice instead of the pie, use angle = a instead of 360-a

On 10/13/2022 7:48 PM, Raymond West wrote:

This'll work, if you are not too greedy 😉

module pie(){
cylinder(h=h,d=d);
}

module slice(){
  translate([0,0,-h])
   linear_extrude (3h)
    polygon(points=[[0,0],[0,d
2],[sin(a)2d,cos(a)2d]]);
}

difference(){
   pie();
   slice();
}

  h=50;
  d=300;
  a=34;

leaves the rest of the pie. If you want the slice, intersection not
difference.

On 13/10/2022 23:58, Bryan Lee wrote:

I need a method to cut a wedge out of a cylinder (or other shape).

Think of it like cutting a slice of pie at a specific angle.

    module wedge(cutangle){
        // returns a wedge of the specified angle

I thought I had a solution that used the intersection of 2 cubes, but
then
my brain broke.  I was able to accomplish the goal by differencing
out the
negative using 3 cubes, but this became a difference() in a
difference() in
a difference() and there the preview render can get ugly.
I would really like a solid shape that I can intersect instead.

Any thoughts?


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

This is simpler, and renders much faster: h=50; d=300; a=34; rotate_extrude(angle = 360-a) square([d/2,h]); // if you want the slice instead of the pie, use angle = a instead of 360-a On 10/13/2022 7:48 PM, Raymond West wrote: > This'll work, if you are not too greedy 😉 > > module pie(){ > cylinder(h=h,d=d); > } > > module slice(){ >   translate([0,0,-h]) >    linear_extrude (3*h) >     polygon(points=[[0,0],[0,d*2],[sin(a)*2*d,cos(a)*2*d]]); > } > > difference(){ >    pie(); >    slice(); > } > >   h=50; >   d=300; >   a=34; > > leaves the rest of the pie. If you want the slice, intersection not > difference. > > On 13/10/2022 23:58, Bryan Lee wrote: >> I need a method to cut a wedge out of a cylinder (or other shape). >> >> Think of it like cutting a slice of pie at a specific angle. >> >>     module wedge(cutangle){ >>         // returns a wedge of the specified angle >> >> I thought I had a solution that used the intersection of 2 cubes, but >> then >> my brain broke.  I was able to accomplish the goal by differencing >> out the >> negative using 3 cubes, but this became a difference() in a >> difference() in >> a difference() and there the preview render can get ugly. >> I would really like a solid shape that I can intersect instead. >> >> Any thoughts? >> _______________________________________________ >> OpenSCAD mailing list >> To unsubscribe send an email to discuss-leave@lists.openscad.org