Fixing our circles

February 19, 2016

Earlier this week we posted a JavaScript tool for drawing circles in Google Earth. We noted that it didn’t seem to be accurate and assumed it was because some of the calculations were being done by approximating the Earth as a sphere.

Thank you to GEB reader DJ for trying it out and letting us know about a bug which resulted in this interesting pattern:

We decided to investigate and try and improve the accuracy of the code as well as fixing the above bug. We ended up finding a number of bugs. The first, is that for drawing circles, we had reused some code we wrote for drawing fireworks to celebrate the new year. The code correctly took into account the fact that latitude and longitude vary in scale, but apart from that used basic trigonometry to draw the circle. This works very well on small scales, but for very large circles problems become obvious, and if you draw a circle over one of the poles it wraps around it as seen below:

A second bug was due to the fact that in geodesic calculations there are two angles that are typically very similar and we were using the wrong one. This tends to only show up over large distances, so it is not something you notice immediately.

Finally, for the code to calculate intersections we decided to stop using the code from Movable-Type, which uses spherical geometry and instead used some code by Charles Karney posted here. The code was intended to be used with the C++ version of GeographicLib so we had to do some translation into JavaScript.

The result of the above corrections is still not perfect, but is certainly a lot more accurate than it was. There is still a bug that causes it to fail when the triangle is very large, but we hope to get that fixed over the weekend.

Our code is written in the latest version of JavaScript, ES6, which works fine in Chrome, but we convert it to ES5 using Babel for greater cross-browser compatibility before using it on the site.

About Timothy Whitehead

Timothy has been using Google Earth since 2004 when it was still called Keyhole before it was renamed Google Earth in 2005 and has been a huge fan ever since. He is a programmer working for Red Wing Aerobatx and lives in Cape Town, South Africa.

Yes, that is how I draw the circle once I have the centre. The hard part was working out where the centre is. Also plotting points equidistant from a given point on the surface of the earth is not a straight forward task without third party libraries. Luckily GeographicLib provides the necessary routines that make that task easy.

Thanks for the accreditation – I was just doing a bit of ‘beta testing’ on an ongoing project/avocation of mine -> mapping everything interesting in the world.

First map I did was on Gold Butte in Nevada – the ‘huggers’ and the BLM have all but closed off the area against seniors and anyone who can’t hike – so I was interested in visualizing some distance calculations to senior-popular sites in the area and got the results you posted.

All the fancy calculations you mentioned seemed like they should about solve mystery of life calculations so I created a “use case” that would stretch even the mighty – It actually completely and totally BORKS the great Google Earth. Just try and create an overlay with these coordinates!

I took three placemarks for a map I’m working on which includes every ‘accepted’ map feature (landmarks) in Antarctica – the three closest which surround the South Pole! If anything would bork, it should be this! Transitioning GPS coordinates around zero. The Patuxent Ice Stream, Maud Subglacial Basin and the Titan Dome – all around the Scott-Amundsen South Pole Station. The above zip file contains: the Kml file I used, the circle.kml that you drew and the screenshot of the result – PERFECT!

This blog and its author are not an official source of information from Google that produces and owns Google Earth
Google and Google Earth are trademarks of Google Inc..
All image screenshots from Google Earth are Copyright Google.
All other trademarks appearing here are the trademarks of their respective owners.