ofPolyline convex hull & areas intersection [Solved]

Hi everyone.

I’m trying to calculate the intersection of the areas delimited by two ofPolyline.
I used the ofxConvexHull addon to generate the convex hulls of two sets of points. Now I need to numerically compare the two convex hulls. Then I thought to calculate the percentage of area that match.

The ofPolyline class provide the useful method getArea(), so it should be enough to determine the extreme points of the intersection of the convex hulls. Does anyone has a method?

The only thing that I have already tried is to double cycle (over width anche hight) overall image pixels and check if every pixel is inside both convex hull. This of course works, but it is really too slow.

Thank you in advance.


To compute the intersection between the 2 convex hulls you can use one of the existing “polygons boolean operation” libraries. Some of them are mentionned here.
There is already this addon which bring one of them, clipper, to OF.
Once you’ve got the intersection you can get its area.

Perhaps Clipper is a little bit overkill because it can deal with any polygons, not only the convex ones. Another approach may be this one:

  • take the intersection points between the sides of the 2 polygons (the red dots in the picture below)
  • take the vertices of each polygon which are contained inside the other one (the blue dots)
  • build the intersection polygon with these points. You have to sort them. Don’t know how, perhaps simply get the convex hull from them.

Or find a polygon boolean code which deal only with convex polygons. I haven’t found one with a quick look, but it must exist.


Thank you lilive, I had the same idea of the intersection points.
Here is my solution to the problem.

polyInteresection.cpp (3,8 KB)