Snippet: Circular sector and arcs with OpenScad

The idea of creating a robust arc module for OpenScad is quite simple: We take two circles with radius \(r_1\) and \(r_2\) and subtract them from eachother. After that we create a triangle from \((0, 0)\) to points on the angles \(\alpha_1\) and \(\alpha_2\) we want to extract:

module arc(r1, r2, a1, a2) {
  difference() {
    difference() {
      polygon([[0,0], [cos(a1) * (r1 + 50), sin(a1) * (r1 + 50)], [cos(a2) * (r1 + 50), sin(a2) * (r1 + 50)]]);
      circle(r = r2);
    }
    difference() {
      circle(r=r1 + 100);
      circle(r=r1);
    }
  }
}

This 2D geometry can be extruded easily with:

linear_extrude(height = h) {
  arc(r1, r2, a1, a2);
}