title: Calculating the intersection area between two rectangles with axes not aligned
body: <p>I want to calculate the intersection over union <em>IoU</em> between two rectangles with axes not aligned, but with an angle of the axes smaller than 30 degrees. An approximate value is also seeked.</p>
  
  <p>One possible solution is to check if the angle between the two rectangles is less than 30 degree and than rotate them parallel to aligne the axis. From here it is easy to calculate the <em>IoU</em>. </p>
  
  <p>Another possibility is to use monte carlo methods for the intersection ( generate a point, find if the point is under some line of one rectangle and above some line of the other), but this seems expensive because I need to use this calculation a large number of times.</p>
  
  <p>I was hopping that there is something better out there; maybe a geometry library, or maybe an algorithm from the computer vision folks.</p>
  
  <p>I am trying to learn grasping positions using deep neural networks. My algorithem should predict a bounding box (rectangle) for an object in an rgb image. For any image I have also the ground truth (another rectangle) bounding box. From this two rectangles I need the <em>IoU</em>.</p>
  
  <p>Any idea?</p>