Is there an easy way to get the lat
/lng
of the intersection points (if available) of two circles in Google Maps API V3? Or should I go with the hard way?
EDIT : In my problem, circles always have the same radius, in case that makes the solution easier.
Yazanpro, sorry for the late response on this.
You may be interested in a concise variant of MBo's approach, which simplifies in two respects :
Here's the function :
No disrespect to MBo by the way - it's an excellent answer.
Yes, for equal circles rather simple solution could be elaborated:
Let's first circle center is A point, second circle center is F, midpoint is C, and intersection points are B,D. ABC is right-angle spherical triangle with right angle C.
We want to find angle A - this is deviation angle from A-F direction. Spherical trigonometry (Napier's rules for right spherical triangles) gives us formula:
cos(A)= tg(AC) * ctg(AB)
where one symbol denote spherical angle, double symbols denote great circle arcs' angles (AB, AC). We can see that AB = circle radius (in radians, of course), AC = half-distance between A and F on the great circle arc. To find AC (and other values) - I'll use code from this excellent pageand our
If circle radius Rd is given is kilometers, then
Now we can find angle
Starting bearing (AF direction):
Intersection points' bearings:
Intersection points' coordinates:
and the same for D_bearing
latB, lonB are in radians
The computation the "hard" way can be simplified for the case r1 = r2 =: r. We still first have to convert the circle centers P1,P2 from (lat,lng) to Cartesian coordinates (x,y,z).
But the intersection line of the planes holding the circles can be computed more easily. Let
d
be the distance of the actual circle center (in the plane) to the corresponding point P1 or P2 on the surface. A simple derivation shows (with R the earth's radius):Now let S1 and S2 be the intersections points and S their mid-point. With
s = |OS|
andt = |SS1| = |SS2|
(where O = (0,0,0) is the earth's center) we get from simple derivations:Now since
r1 = r2
the points S, S1, S2 are in the mid-plane between P1 and P2. Forv_s = OS
we get:Finally we have to convert back to (lat,lng):