title: Area of self-intersecting polygon
body: <p>Calculating the area of a <em>simple irregular</em> polygon <a href="http://www.mathopenref.com/coordpolygonarea2.html" rel="noreferrer">is trivial</a>. However, consider the self-intersecting polygon ABCDEF shown at left below:</p>
  
  <p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <img src="https://i.stack.imgur.com/j9XSK.png" alt="A self-intersecting polygon shaped like a &#39;figure 8&#39;"></p>
  
  <p>If we use the linked-to formula above traversing the points in polygon order, we get an area of 0. (The 'clockwise' area cancels out the 'counter-clockwise' area.)</p>
  
  <p>However, if we <a href="https://stackoverflow.com/questions/6989100/sort-points-in-clockwise-order">sort the points radially around a center</a> and calculate the area, we get the incorrect area of the polygon ABEDCF at right above.</p>
  
  <p>How can I best find the visible area of a self-intersecting polygon? (If the answer requires creating phantom points for each intersection, please provide details for how to best find the intersections and how then to traverse them in correct order.)</p>
  
  <p><em>This question arose when investigating edge cases for my solution to <a href="https://stackoverflow.com/a/10045537/405017">this question</a>.</em></p>
  
  <h2>Defining the Area</h2>
  
  <p>I define the 'area' as the amount of pixels visible when filling the polygon using either the "nonzero" or "evenodd" rules. I will accept an answer for either of these, though both would be better. Note that I explicitly do <em>not</em> define the area for self-overlapping to count the overlapping area twice.</p>
  
  <p><img src="https://i.stack.imgur.com/sDS2W.png" alt="enter image description here"></p>