title: How to find the smallest sector of a circle that covers a polygon?
body: <p>Given the circle C: (O, r) and the polygon P, how can I find the smallest sector of C that covers P?</p>
  <p><a href="https://i.stack.imgur.com/Oh6F5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Oh6F5.png" alt="enter image description here" /></a></p>
  <p>Assume that the radius of the circle is large enough, so the main problem is to find the initial and final angles of the sector.</p>
  <p>I tried to draw rays from center of circle toward each of angles of the polygon and check if the ray overlaps the polygon. But there might be more than two rays that only touch the polygon. I can not rely on the selection of unique rays based on their direction angle, due to double precision. So finding min and max angles in the list of touched rays is useless. Beside that, I have problem with choosing either of sectors created by two terminal angles, since initial angle can be greater than final angle when computed by <code>atan2</code>.
  <a href="https://i.stack.imgur.com/U8u80.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U8u80.png" alt="enter image description here" /></a></p>
  <p>So what is the proper way to find such a sector?</p>
  <p><strong>Edit:</strong>
  Three example polygons (in WKT format):</p>
  <pre><code>POLYGON((52.87404 30.85613, 42.55699 28.46292, 41.54373 24.319989, 53.57623 21.300564, 62.94891 28.46292, 49.39652 27.550071, 52.87404 30.85613))
  POLYGON((52.94294 30.920592, 42.55699 28.46292, 43.61965 35.545578, 55.85037 34.862696, 59.12524 36.621547, 47.68664 39.877048, 35.69973 36.198265, 37.30512 29.196711, 31.09762 28.46292, 41.54373 24.319989, 53.57623 21.300564, 62.94891 28.46292, 49.39652 27.550071, 52.94294 30.920592))
  POLYGON((52.94294 30.920592, 42.55699 28.46292, 43.61965 35.545578, 52.45594 37.266299, 59.30560 29.196711, 64.12177 33.290489, 58.81733 36.554277, 47.68664 39.877048, 35.69973 36.198265, 37.30512 29.196711, 31.09762 28.46292, 41.54373 24.319989, 53.57623 21.300564, 62.94891 28.46292, 49.39652 27.550071, 52.94294 30.920592))
  </code></pre>
  <p>Center and radius of circle for all examples:</p>
  <pre><code>O: (45, 30)
  r: 25
  </code></pre>