Showing posts with label Work. Show all posts
Showing posts with label Work. Show all posts

Friday, November 7, 2008

Oblate Spheroid Geometry

I know what you’re thinking, the title sounds scary so I will just skip over this post. Well, you would be missing out, because I have a pretty interesting side project at work. The problem is fairly straight forward: find the distance (km) between two different points of latitude and longitude. I need to write a function (JavaScript, ColdFusion, etc) to calculate exactly how far Los Angeles is from London. However, the solution could be problematic.

In the perfect world, we could assume the world is a perfect sphere. If we assume this, an equation like this would solve:

Given Location1 = (Latitude1, Longitude1) and Location2 = (Latitude2, Longitude2) in degrees:

Convert the latitudes and longitudes from degrees to radians.
Lat1 = (Pi * Latitude1)/180
Long1 = (Pi * Longitude1)/180
Lat2 = (Pi * Latitude2)/180
Long2 = (Pi * Longitude2)/180
Radius of the Earth= 6378.1 km

Distance = Radius * ARCOS(SIN(Lat1)SIN(Lat2) + COS(Lat1)COS(Lat2)COS(Long1 – Long2))

But what if that isn’t good enough? The world is not a perfect sphere; it is more accurately represented as an Oblate Spheroid. That’s right; our world is actually about 42 km wider than it is tall. This throws a wrench into the calculations. That wrench does have a name, and it is called calculus. I’ve been doing some research and could elaborate further, but don’t want to throw too much math into one post.



*I would also like to add that both of these scenarios assume elevation is unimportant. Trying to calculate distance accurately across the contour of the earth exponentially increases the difficulty of these calculations.

If you have any ideas or questions, leave a comment.