discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Cutting a pie slice

BL
Bryan Lee
Thu, Oct 13, 2022 10:58 PM

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?

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?
W
Whosawhatsis
Thu, Oct 13, 2022 11:04 PM

rotate_extrude() takes an angle, which makes this really easy.
On Oct 13, 2022, 15:58 -0700, Bryan Lee leebc11@acm.org, 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

rotate_extrude() takes an angle, which makes this really easy. On Oct 13, 2022, 15:58 -0700, Bryan Lee <leebc11@acm.org>, 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
RW
Raymond West
Thu, Oct 13, 2022 11:48 PM

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'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
BC
Bob Carlson
Fri, Oct 14, 2022 12:05 AM

Use pie_slice() from shapes3d.scad in BOSL2 and either intersect or difference.

-Bob
Tucson AZ

On Oct 13, 2022, at 15:58, Bryan Lee leebc11@acm.org 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

Use pie_slice() from shapes3d.scad in BOSL2 and either intersect or difference. -Bob Tucson AZ On Oct 13, 2022, at 15:58, Bryan Lee <leebc11@acm.org> 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
N
neri-engineering
Fri, Oct 14, 2022 1:40 AM

You bring up a non-trivial problem that requires some delicate thought especially if using an older version of OpenSCAD from e.g. 2015.  This is the snippet of production code that I use.  It is needed in lots of my code in fact.  The end of the code (with the linear_extrude) has the sample which you can tweak to verify that the results you get are adequate.  The code handles all combinations of start angle and end angle, modulo bugs of course, and at the moment none are affecting me.

// Returns the equivalent angle but in the range [0,360).  Negative and
// positive values accepted.
function angle_wrap(angle)=angle-floor(angle/360)*360;

// __________________________________________________________
// | start_angle | end_angle  | test_angle  | outcome      |
// +-------------+-------------+-------------+--------------+
// | 30          | 45          | 37          | +++  ->  +1  |
// | 30          | 45          | 0          | +-+  ->  -1  |
// | 30          | 45          | 100        | ++-  ->  -1  |
// | 30          | 45          | 30          | +0+  ->  0  |
// | 30          | 45          | 45          | ++0  ->  0  |
// | 270        | 30          | 359        | -+-  ->  +1  |
// | 270        | 30          | 60          | ---  ->  -1  |
// | 270        | 30          | 25          | --+  ->  +1  |
// | 270        | 30          | 270        | -0-  ->  0  |
// | 270        | 30          | 30          | --0  ->  0  |
// +-------------+-------------+-------------+--------------+
// | 50          | 50          | 10          | +-+  ->  -1  |
// | 50          | 50          | 200        | ++-  ->  -1  |
// | 50          | 50          | 50          | +00  ->  0  |
// ----------------------------------------------------------
function angle_between(start_angle,end_angle,test_angle)=
sign((sign(end_angle  - start_angle) + 0.5)
*(test_angle - start_angle)
*(end_angle  - test_angle));

module wedge_2d(start_angle,
end_angle,
box_radius)
{
for(rot=[0:90:359]) {
_start_angle=angle_wrap(start_angle+rot);
_end_angle=angle_wrap(end_angle+rot);
rotate([0,0,-rot]) {
if(angle_between(_start_angle,_end_angle,0)>=0 &&
angle_between(_start_angle,_end_angle,90)>=0 &&
_end_angle>=90) {
square(box_radius); // Include the entire quadrant.
} else {
if(angle_between(0,90,_start_angle)>=0 &&
_start_angle<90 &&
_start_angle!=_end_angle) {
intersection() {
difference() {
rotate([0,0,_start_angle]) {
square(box_radius2);
}
if(_end_angle>_start_angle &&
angle_between(0,90,_end_angle)>0) {
rotate([0,0,_end_angle]) {
square(box_radius
2);
}
}
}
square(box_radius);
}
}
if(angle_between(0,90,_end_angle)>0 &&
_start_angle>_end_angle) {
intersection() {
rotate([0,0,-90+_end_angle]) {
square(box_radius*2);
}
square(box_radius);
}
}
}
}
}
}

linear_extrude(height=10,
center=true,
convexity=2)
{
wedge_2d(start_angle=25,
end_angle=-45,
box_radius=8);
}

Sent with Proton Mail secure email.

------- Original Message -------
On Thursday, October 13th, 2022 at 5:58 PM, Bryan Lee leebc11@acm.org 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

You bring up a non-trivial problem that requires some delicate thought especially if using an older version of OpenSCAD from e.g. 2015. This is the snippet of production code that I use. It is needed in lots of my code in fact. The end of the code (with the linear_extrude) has the sample which you can tweak to verify that the results you get are adequate. The code handles all combinations of start angle and end angle, modulo bugs of course, and at the moment none are affecting me. // Returns the equivalent angle but in the range [0,360). Negative and // positive values accepted. function angle_wrap(angle)=angle-floor(angle/360)*360; // __________________________________________________________ // | start_angle | end_angle | test_angle | outcome | // +-------------+-------------+-------------+--------------+ // | 30 | 45 | 37 | +++ -> +1 | // | 30 | 45 | 0 | +-+ -> -1 | // | 30 | 45 | 100 | ++- -> -1 | // | 30 | 45 | 30 | +0+ -> 0 | // | 30 | 45 | 45 | ++0 -> 0 | // | 270 | 30 | 359 | -+- -> +1 | // | 270 | 30 | 60 | --- -> -1 | // | 270 | 30 | 25 | --+ -> +1 | // | 270 | 30 | 270 | -0- -> 0 | // | 270 | 30 | 30 | --0 -> 0 | // +-------------+-------------+-------------+--------------+ // | 50 | 50 | 10 | +-+ -> -1 | // | 50 | 50 | 200 | ++- -> -1 | // | 50 | 50 | 50 | +00 -> 0 | // ---------------------------------------------------------- function angle_between(start_angle,end_angle,test_angle)= sign((sign(end_angle - start_angle) + 0.5) *(test_angle - start_angle) *(end_angle - test_angle)); module wedge_2d(start_angle, end_angle, box_radius) { for(rot=[0:90:359]) { _start_angle=angle_wrap(start_angle+rot); _end_angle=angle_wrap(end_angle+rot); rotate([0,0,-rot]) { if(angle_between(_start_angle,_end_angle,0)>=0 && angle_between(_start_angle,_end_angle,90)>=0 && _end_angle>=90) { square(box_radius); // Include the entire quadrant. } else { if(angle_between(0,90,_start_angle)>=0 && _start_angle<90 && _start_angle!=_end_angle) { intersection() { difference() { rotate([0,0,_start_angle]) { square(box_radius*2); } if(_end_angle>_start_angle && angle_between(0,90,_end_angle)>0) { rotate([0,0,_end_angle]) { square(box_radius*2); } } } square(box_radius); } } if(angle_between(0,90,_end_angle)>0 && _start_angle>_end_angle) { intersection() { rotate([0,0,-90+_end_angle]) { square(box_radius*2); } square(box_radius); } } } } } } linear_extrude(height=10, center=true, convexity=2) { wedge_2d(start_angle=25, end_angle=-45, box_radius=8); } Sent with Proton Mail secure email. ------- Original Message ------- On Thursday, October 13th, 2022 at 5:58 PM, Bryan Lee <leebc11@acm.org> 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
SP
Sanjeev Prabhakar
Fri, Oct 14, 2022 2:25 AM

As per me the following should be a very clean solution:

  1. find intersection points between a cylinder (or whatever shape) and
    titled surface
    2.copy the intersection points by whatever distance you want the thickness
    of the pie
  2. create a polyhedron from these 2 set of points.

I have written the code in jupyter notebook and is attached here in case
you want to experiment.

[image: Screenshot 2022-10-14 at 7.44.38 AM.png]
you need to change the file pathname and location.
you would also need dependencies.scad to visualise the points, or otherwise
remove the lines in the code where "points" function is referred

On Fri, 14 Oct 2022 at 04:28, Bryan Lee leebc11@acm.org 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

As per me the following should be a very clean solution: 1. find intersection points between a cylinder (or whatever shape) and titled surface 2.copy the intersection points by whatever distance you want the thickness of the pie 3. create a polyhedron from these 2 set of points. I have written the code in jupyter notebook and is attached here in case you want to experiment. [image: Screenshot 2022-10-14 at 7.44.38 AM.png] you need to change the file pathname and location. you would also need dependencies.scad to visualise the points, or otherwise remove the lines in the code where "points" function is referred On Fri, 14 Oct 2022 at 04:28, Bryan Lee <leebc11@acm.org> 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 >
JB
Jordan Brown
Fri, Oct 14, 2022 3:27 AM

On 10/13/2022 3:58 PM, Bryan Lee wrote:

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.

Whosawhatsis had the right answer:  rotate_extrude with an angle.

But just for fun I thought I'd look at the "intersect with two cubes"
solution.

You don't say whether you need the full 360° range, or if a smaller
range will work for you.

If you need less than 90°, this will work for you:

// Make a unit-radius pie slice of the specified angle,
// 90 degrees or less.
module pie1(a) {
    intersection() {
        circle($fn=50);
        // The squares are 2 so that they don't touch the circle.
        square(2);
        rotate(a-90) square(2);
    }
}

If you need less than 180°, this variation (using what are effectively
half-planes instead of squares) will work:

// Make a unit-radius pie slice of the specified angle,
// 180 degrees or less.
module pie2(a) {
    intersection() {
        circle($fn=50);
        // The squares are 4 so that they don't touch the circle
        // after centering.
        translate([-2,0,0]) square(4);
        rotate(a-180) translate([-2,0,0]) square(4);
    }
}

If you need more than 180° then I don't think there's any simple
intersect/difference answer, but you can always build a 180° slice and
add it to a smaller slice:

// Make a unit-radius pie slice of the specified angle.
module pie3(a) {
    if (a <= 180) {
        pie2(a);
    } else {
        pie2(180);
        rotate(180) pie2(a-180);
    }
}

Or subtract a <180° slice from a circle:

// Make a unit-radius pie slice of the specified angle.
module pie4(a) {
    if (a <= 180) {
        pie2(a);
    } else {
        difference() {
            circle();
            // Scale up the slice we're removing so that it
            // doesn't touch the circle.
            // Rotate it so that it's in the right place.
            // For extra credit, find an answer that needs only
            // a scale, with no rotate.
            rotate(a-360) scale(2) pie2(360-a);
        }
    }
}

And to test and demonstrate, an animation is fun:

angle = 360*$t;
translate([5,2]) text(str(round(angle),"\u00ba"), size=1, halign="center");
pie1(angle);
translate([3,0,0]) pie2(angle);
translate([6,0,0]) pie3(angle);
translate([9,0,0]) pie4(angle);

(Intro to animation, if necessary:  View/Animate, and then in the boxes
at the bottom set FPS to 10 and Steps to 90.)

Generalizing to sizes larger than unit is left as an exercise for the
reader.

Generalizing to three dimensions is left as an exercise for the reader.

On 10/13/2022 3:58 PM, Bryan Lee wrote: > 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. Whosawhatsis had the right answer:  rotate_extrude with an angle. But just for fun I thought I'd look at the "intersect with two cubes" solution. You don't say whether you need the full 360° range, or if a smaller range will work for you. If you need less than 90°, this will work for you: // Make a unit-radius pie slice of the specified angle, // 90 degrees or less. module pie1(a) { intersection() { circle($fn=50); // The squares are 2 so that they don't touch the circle. square(2); rotate(a-90) square(2); } } If you need less than 180°, this variation (using what are effectively half-planes instead of squares) will work: // Make a unit-radius pie slice of the specified angle, // 180 degrees or less. module pie2(a) { intersection() { circle($fn=50); // The squares are 4 so that they don't touch the circle // after centering. translate([-2,0,0]) square(4); rotate(a-180) translate([-2,0,0]) square(4); } } If you need more than 180° then I don't think there's any simple intersect/difference answer, but you can always build a 180° slice and add it to a smaller slice: // Make a unit-radius pie slice of the specified angle. module pie3(a) { if (a <= 180) { pie2(a); } else { pie2(180); rotate(180) pie2(a-180); } } Or subtract a <180° slice from a circle: // Make a unit-radius pie slice of the specified angle. module pie4(a) { if (a <= 180) { pie2(a); } else { difference() { circle(); // Scale up the slice we're removing so that it // doesn't touch the circle. // Rotate it so that it's in the right place. // For extra credit, find an answer that needs only // a scale, with no rotate. rotate(a-360) scale(2) pie2(360-a); } } } And to test and demonstrate, an animation is fun: angle = 360*$t; translate([5,2]) text(str(round(angle),"\u00ba"), size=1, halign="center"); pie1(angle); translate([3,0,0]) pie2(angle); translate([6,0,0]) pie3(angle); translate([9,0,0]) pie4(angle); (Intro to animation, if necessary:  View/Animate, and then in the boxes at the bottom set FPS to 10 and Steps to 90.) Generalizing to sizes larger than unit is left as an exercise for the reader. Generalizing to three dimensions is left as an exercise for the reader.
JB
Jordan Brown
Fri, Oct 14, 2022 4:13 AM

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.
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.
SP
Sanjeev Prabhakar
Fri, Oct 14, 2022 4:48 AM

It seems I totally wrong in understanding what you are looking for.
Can you please make a sketch to clarify

On Fri, 14 Oct, 2022, 4:28 am Bryan Lee, leebc11@acm.org 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

It seems I totally wrong in understanding what you are looking for. Can you please make a sketch to clarify On Fri, 14 Oct, 2022, 4:28 am Bryan Lee, <leebc11@acm.org> 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 >
MM
Michael Marx
Fri, Oct 14, 2022 4:49 AM

Generalising to a transformation operator to apply to children is left as an exercise for the reader.

remove_slice(start_degree, end_degree) yourObject();


From: Jordan Brown []
Sent: Fri, 14 Oct 2022 14:28
To: OpenSCAD general discussion Mailing-list; Bryan Lee

Generalizing to sizes larger than unit is left as an exercise for the reader.

Generalizing to three dimensions is left as an exercise for the reader.

--
This email has been checked for viruses by AVG antivirus software.
www.avg.com

Generalising to a transformation operator to apply to children is left as an exercise for the reader. remove_slice(start_degree, end_degree) yourObject(); _____ From: Jordan Brown [] Sent: Fri, 14 Oct 2022 14:28 To: OpenSCAD general discussion Mailing-list; Bryan Lee Generalizing to sizes larger than unit is left as an exercise for the reader. Generalizing to three dimensions is left as an exercise for the reader. -- This email has been checked for viruses by AVG antivirus software. www.avg.com