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.
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:
- GeographicLib can be found here
- The code specific to drawing circles
- Our KML library (still in development)