Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm getting the distance between two locations (lat/long) using Pythagoras theorem.

my data look like this (I use microdegrees because I have limitations)

point1: -34608420,-58373160
point2: -34609420,-58374160

I have a few limitation, I'm building an application for a cell phone and using decimals and functions like $\sin, \cos$ are very expensive and take a lot of time. Also, I'm doing this calculation more than $1000$ times.

Pythagoras works fine, but I need to convert the result distance to meters. The radius is the Earth's radius.

I do not care about precession because the points are very close too each other and the arc would not be much.


How can I convert the resulting distance using Pythagoras to meters? Is there a better way to do it, than using Pythagoras?

Thanks, Federico

share|cite|improve this question
Can you use taylor approximations to sin and cos? I don't think polynomials cost a lot of time now do they? – Patrick Da Silva Jan 6 '12 at 22:12
There are pretty much 3 algorithms to simulate the trig functions: CORDIC, taylor series, and table lookup. Choice depends on your exact constraints. If you're processor constrained but the processor is better than a microcontroller, which I assume is the case for a cell phone, table lookup might be fastest. – Mark Beadles Jan 7 '12 at 0:44

For small distances, the north/south distance is $R(\lambda_2-\lambda_1)$, where $R$ is the radius of the earth and $\lambda$ is latitude. The east/west distance is $R\cos \lambda (\phi_2-\phi_1)$ where $\phi$ is longitude. You can then use Pythagoras on these linear dimensions. The only problem is the $\cos \lambda$, which you can't get away from because the lines of longitude get closer as you get to the poles. You could store a table of cosines, maybe every $5$ degrees, and interpolate, to save the time.

share|cite|improve this answer
+1 for suggesting table lookup – Mark Beadles Jan 7 '12 at 0:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.