berca
berca

Reputation: 36

How to find and graph the intersection of 3+ circles with Matplotlib

I'm working on a problem that involves creating a graph which shows the areas of intersection of three or more circles (each circle is the same size). I have many sets of circles, each set containing at least three circles. I need to graph the area common to the interior of each and every circle in the set, if it even exists. If there is no area where all the circles within the set intersect, I have nothing to graph. So the final product is a graph with little "slivers" of intersecting circles all over.

I already have a solution for this written in Python with matplotlib, but it doesn't perform very well. This wasn't an issue before, but now I need to apply it to a larger data set so I need a better solution. My current approach is basically a test-and-check brute force method: I check individual points within an area to see if they are in that common intersection (by checking distance from the point to the center of each circle). If the point meets that criteria, I graph it and move on. Otherwise, I just don't graph it and move on. So it works, but it takes forever.

Just to clarify, I don't scan through every point in the entire plane for each set of circles. First, I narrow my "search" area to a rectangle tightly bounded around the first two (arbitrarily chosen) circles in the set, and then test-and-check each point in there.

I was thinking it would be nice if there were a way for me to graph each circle in a set (say there 5 circles in the set), each with an alpha value of 0.1. Then, I could go back through and only keep the areas with an alpha value of 0.5, because that's the area where all 5 circles intersect, which is all I want. I can't figure out how to implement this using matplotlib, or using anything else, for that matter, without resorting to the same brute force test-and-check strategy.

I'm also familiar with Java and C++, if anyone has a good idea involving those languages. Thank you!

Upvotes: 0

Views: 1453

Answers (1)

DrV
DrV

Reputation: 23490

Maybe you should try something more analytical? It should not be very difficult:

  1. Find the circle pairs whose distance is less than the sum of their radii; they intersect.

  2. Calculate the intersection angles by simple trigonometry.

  3. Draw a polygon (path) by using a suitably small delta angle in both cases (half of the polygon comes from one circle, the other half from the other circle.

  4. Collect the paths to a PathCollection

None of the steps should be very long or difficult.

Upvotes: 1

Related Questions