-1

I am developing an android app which involves calculating the total area covered by a set of circles on a map.

Say I have a List of Circles, each Circle has fields double longitude, double latitude, and double radius.

List<Circles> circles;

class Circle {
    double longitude;
    double latitude;
    double radius;
}

These circles may or may not overlap, they can be a thousand miles away from each other or they can be all piled up on top of each other.

I want to calculate the total combined area of these Circles (with their overlapping taken into account of course). What would be a good algorithm (or a library function if there exists) to use for this purpose?

StormSailing
  • 21
  • 2
  • 6
  • 1
    This is more of a mathematical problem rather than a programming one. You need to find a formula that calculates the area of overlapping circles. – Mushif Ali Nawaz Oct 14 '19 at 06:12
  • 1
    Check this out https://stackoverflow.com/questions/1667310/combined-area-of-overlapping-circles/1667789#1667789 – Madstuffs Oct 14 '19 at 06:15
  • Asking for tools, libraries, tutorials, or off-site resources recommendation is off-topic in here – Andreas Oct 14 '19 at 06:19
  • 1
    _I am developing an android app_ There is a limit of no more than five tags per question. I suggest you remove one of the tags and replace it with the [android](https://stackoverflow.com/tags/android/info) tag in order to attract Android developers who may be able to help you. – Abra Oct 14 '19 at 08:00
  • @Abra thank you for your suggestion, but I think the problem is less related to the domain of Android, but more of a generic algorithm question, that's why I didn't put Android in there to avoid perplexing the context. – StormSailing Oct 14 '19 at 08:15
  • I first voted to close this as a duplicate of the question to which @Madstuffs refers. But on reflection, this requires the computation of the area of *spherical caps* not of circles. It ain't just pi-r-squared. – High Performance Mark Oct 17 '19 at 10:27

1 Answers1

0

First you need to cluster the overlapping circles:

Make each circle its own cluster
Repeat (until convergence):
  For each cluster:
     For each other cluster:
        Merge clusters if any of their circles overlap

Then you calculate the area of each cluster using Combined area of overlapping circles.

Finally, you sum all clusters.

Pibben
  • 1,876
  • 14
  • 28