<p>This is what I use:</p>

<pre><code>module pieSlice(a, r, h){
  // a:angle, r:radius, h:height
  rotate_extrude(angle=a) square([r,h]);
}
pieSlice(110,20,3);
</code></pre>

CC BY-SA 4.0
2019-09-27T16:49:21.297Z
2019-09-27T16:49:21.297Z
CFreitas
<p>My current workaround is to use <code>union</code> instead of intersection. Unfortunately, that means I have to use an <code>if</code> clause which makes the code have two paths instead of one clean approach. Also, unlike the above method, this does not result in a clean cylindrical shape but must instead by combined with a proper cylinder to get the final pie slice   </p>

<pre><code>   size = length + 2;
    if (angle_deg &lt;= 90) {
      translate([0,0,-1]) 
      intersection() {
        cube(size);
        rotate(angle_deg-90) cube(size);
      }
    } else if (angle_deg &lt;= 180) {
      translate([0,0,-1]) 
      union() {
        cube(size);
        rotate(angle_deg-90) cube(size);
      }      
    } else {
      echo(str("FAILURE - Angle cannot exceed 180"));
    } 


</code></pre>

CC BY-SA 4.0
2019-07-20T22:31:59.410Z
2019-07-20T22:31:59.410Z
Hamy
<p>Although generating complex shapes by combining primitive OpenSCAD shapes is a well-established tradition, and is often all that is needed, it would be more elegant in this case to generate a pie slice directly using the <code>polygon</code> function and a list comprehension.</p>

<pre><code>module pie_slice(r=3.0, a=30) {
  polygon(points=[
    [0, 0],
    for(theta=0; theta&lt;a; theta=theta+$fa)
      [r*cos(theta), r*sin(theta)],
    [r*cos(a), r*sin(a)]
  ]);
}
</code></pre>

<p>Note that the above code is a little crude, since it does no error checking, but it works. It uses the <code>$fa</code> special variable for the step angle.</p>

CC BY-SA 4.0
2019-07-23T14:06:44.753Z
2019-07-23T14:06:44.753Z
Mick
<p>When making a cylinder, sometimes I need to only take a pie slice. I'm currently using <a href="http://forum.openscad.org/Creating-pie-pizza-slice-shape-need-a-dynamic-length-array-tp3148p3149.html" rel="noreferrer">this</a> neat trick to make pie slices for angles under 90 degrees. However, I have need of a few angles over 90 but under 180 degrees. Is there a way to generalize/extend this to work for these bigger angles? </p>

<pre><code>module pie_slice(r=3.0,a=30) {     
   intersection() {
    circle(r=r);
    square(r);
    rotate(a-90) square(r);  
  } 
}

pie_slice(r=10,a=15);
</code></pre>

CC BY-SA 4.0
2019-07-20T22:19:45.440Z
I think the easiest would be to use `difference`. Circle minus two cubes with sides 2*R. (Or one of size 2*R and one of size R.)
Tomas By
CC BY-SA 4.0
2019-07-20T22:33:44.647Z
IIUC, this is similar to my current workaround (I've posted below for reference). I use `union` instead of `intersection`. Unfortunately, you have to examine how many degrees the caller wants and use one or the other - I have yet to find a universal method
Hamy
CC BY-SA 4.0
2019-07-20T22:38:41.743Z
Think of it this way: you have two rectangles that cover each half of the circle. Then you open a gap between them of the angle. That should work for any angle between 0 and 180.
Tomas By
CC BY-SA 4.0
2019-07-20T22:46:07.570Z
Oh snap, that sounds perfect. I'll give it a try, thanks
Hamy
CC BY-SA 4.0
2019-07-21T06:58:41.580Z
Or use a module that can make pie slices, e.g. [Chamfers-for-OpenSCAD](https://github.com/SebiTimeWaster/Chamfers-for-OpenSCAD).
0scar
<3d-models><3d-design><openscad>
Creating "pie slice" in OpenSCAD?
Hamy
# Creating "pie slice" in OpenSCAD?

(Asked by: username_0 on 2019-07-20)

When making a cylinder, sometimes I need to only take a pie slice. I'm currently using [this](http://forum.openscad.org/Creating-pie-pizza-slice-shape-need-a-dynamic-length-array-tp3148p3149.html) neat trick to make pie slices for angles under 90 degrees. However, I have need of a few angles over 90 but under 180 degrees. Is there a way to generalize/extend this to work for these bigger angles?

```
module pie_slice(r=3.0,a=30) {     
   intersection() {
    circle(r=r);
    square(r);
    rotate(a-90) square(r);  
  } 
}

pie_slice(r=10,a=15);

```

**Tags:** 3d-models, 3d-design, openscad

> **Comments:**
> **username_1**: I think the easiest would be to use `difference`. Circle minus two cubes with sides 2*R. (Or one of size 2*R and one of size R.)  
> **username_0**: IIUC, this is similar to my current workaround (I've posted below for reference). I use `union` instead of `intersection`. Unfortunately, you have to examine how many degrees the caller wants and use one or the other - I have yet to find a universal method  
> **username_1**: Think of it this way: you have two rectangles that cover each half of the circle. Then you open a gap between them of the angle. That should work for any angle between 0 and 180.  
> **username_0**: Oh snap, that sounds perfect. I'll give it a try, thanks  
> **username_2**: Or use a module that can make pie slices, e.g. [Chamfers-for-OpenSCAD](https://github.com/SebiTimeWaster/Chamfers-for-OpenSCAD).  

---

## 3 answers

### Answer by username_3 on 2019-09-27. Score: 4

This is what I use:

```
module pieSlice(a, r, h){
  // a:angle, r:radius, h:height
  rotate_extrude(angle=a) square([r,h]);
}
pieSlice(110,20,3);

```


---

### Answer by username_0 on 2019-07-20. Score: 1

My current workaround is to use `union` instead of intersection. Unfortunately, that means I have to use an `if` clause which makes the code have two paths instead of one clean approach. Also, unlike the above method, this does not result in a clean cylindrical shape but must instead by combined with a proper cylinder to get the final pie slice

```
   size = length + 2;
    if (angle_deg <= 90) {
      translate([0,0,-1]) 
      intersection() {
        cube(size);
        rotate(angle_deg-90) cube(size);
      }
    } else if (angle_deg <= 180) {
      translate([0,0,-1]) 
      union() {
        cube(size);
        rotate(angle_deg-90) cube(size);
      }      
    } else {
      echo(str("FAILURE - Angle cannot exceed 180"));
    } 

```


---

### Answer by username_4 on 2019-07-23. Score: 1

Although generating complex shapes by combining primitive OpenSCAD shapes is a well-established tradition, and is often all that is needed, it would be more elegant in this case to generate a pie slice directly using the `polygon` function and a list comprehension.

```
module pie_slice(r=3.0, a=30) {
  polygon(points=[
    [0, 0],
    for(theta=0; theta<a; theta=theta+$fa)
      [r*cos(theta), r*sin(theta)],
    [r*cos(a), r*sin(a)]
  ]);
}

```

Note that the above code is a little crude, since it does no error checking, but it works. It uses the `$fa` special variable for the step angle.


---

