Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Geolocations - How to check if 2 circles are overlapping

Let's say we have 2 locations (latitude,longitude) and each location has a radius (it may be different from each other), making a circle. How to check if these 2 circles are overlapping?

enter image description here

like image 447
Senpai Avatar asked Nov 15 '15 19:11

Senpai


1 Answers

Check if the distance between the centers is smaller than the sum of the radii.

Say for circles A and B with radius Ar and Br respectively, and coordinates (Ax, Ay) and (Bx, By) respectively, the distance between the circles is

    D = sqrt( (Ax - Bx)2 + (Ay - By)2 )

They overlap when

    D < Ar + Br

There's a catch, however: the centers of the circles are placed on a sphere. The shortest distance between them is a straight line, beneath the sphere's surface. The distance between them following the surface will be larger. For instance, the distance between the North and South pole is 2 Earth radii, but the path on the surface will be Earth radii. Also, these circles don't overlap. So, the above equations only hold when the distances are relatively small.

like image 177
Kenney Avatar answered Sep 18 '22 18:09

Kenney