My Google Map Blog

Archive for February 19th, 2016

Fixing our circles

by Timothy Whitehead on Feb.19, 2016, under 3D Models, Argentina, Australia, Brazil, California, Denmark, England, Germany, Google Earth News, Google Earth Tips, Google Sky, Google maps, Hawaii, Indonesia, Ireland, Italy, Japan, Kenya, Mexico, Natural Landmarks, Netherlands, Sightseeing, Street Views, USA

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.

For those interested in the code:

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.

The post Fixing our circles appeared first on Google Earth Blog.

Comments Off :, more...



Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...