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

[{'answer_id': 10639, 'author': 'Hamy', 'author_id': 16835, 'author_profile': 'https://3dprinting.stackexchange.com/users/16835', 'pm_score': 1, 'selected': False, 'text': '<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>\n\n<pre><code>   size = length + 2;\n    if (angle_deg &lt;= 90) {\n      translate([0,0,-1]) \n      intersection() {\n        cube(size);\n        rotate(angle_deg-90) cube(size);\n      }\n    } else if (angle_deg &lt;= 180) {\n      translate([0,0,-1]) \n      union() {\n        cube(size);\n        rotate(angle_deg-90) cube(size);\n      }      \n    } else {\n      echo(str("FAILURE - Angle cannot exceed 180"));\n    } \n\n\n</code></pre>\n'}, {'answer_id': 10663, 'author': 'Mick', 'author_id': 3953, 'author_profile': 'https://3dprinting.stackexchange.com/users/3953', 'pm_score': 0, 'selected': False, 'text': '<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>\n\n<pre><code>module pie_slice(r=3.0, a=30) {\n  polygon(points=[\n    [0, 0],\n    for(theta=0; theta&lt;a; theta=theta+$fa)\n      [r*cos(theta), r*sin(theta)],\n    [r*cos(a), r*sin(a)]\n  ]);\n}\n</code></pre>\n\n<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>\n'}, {'answer_id': 11093, 'author': 'CFreitas', 'author_id': 13390, 'author_profile': 'https://3dprinting.stackexchange.com/users/13390', 'pm_score': 2, 'selected': False, 'text': '<p>This is what I use:</p>\n\n<pre><code>module pieSlice(a, r, h){\n  // a:angle, r:radius, h:height\n  rotate_extrude(angle=a) square([r,h]);\n}\npieSlice(110,20,3);\n</code></pre>\n'}]
['https://3dprinting.stackexchange.com/questions/10638', 'https://3dprinting.stackexchange.com', 'https://3dprinting.stackexchange.com/users/16835/']