15,791,963 members
1.00/5 (1 vote)
See more:
C#
```(float X1,float Y1,float X2,float Y2)
{
float dx = X1 - X2;
float dy = Y1 - Y2;
float sx = (float)cos( Y1 * 0.01745329252f);
return ((float)sqrt(dx * dx * sx * sx + dy * dy) * 111195.0f);
}```

I found a implementation like this. What is its meaning ?
Posted

## Solution 2

I can't recognize the mentioned math. The simplest way to calculate two points distance is

C++
```float GetDistance(float X1,float Y1,float X2,float Y2)
{
float dx = X1 - X2;
float dy = Y1 - Y2;
return (float)sqrt(dx * dx + dy * dy);
}```

Check this Distance between two points (given their coordinates)[^] for detail

## Solution 3

This is an approximation formula for the distance of two points on a sphere. The factor 0.0174... is PI / 180. That tells us that the Y values are provided in degrees. The multiplication with PI/180 converts the value to radiant.

The multiplication of dx*dx with sx*sx is the compensation for the fact that meridians run closer together in higher latitudes.

The factor 111195 corresponds to distance of one degree on the surface of the earth.

So in summary: The X und Y values are latitude and longitude in degrees and the formula delivers the distance of the two points in meters. It works only if the two points are relatively close together.

v2
Comments
_Asif_ 27-Aug-14 7:06am
+5 for the explanation, i have googled earlier but there was nothing of this sort.
nv3 27-Aug-14 11:23am
You are welcome.

## Solution 1

It's just implementing Pythagoras theorem[^]

Treat the two points as the two ends of the hypotenuse of a right angle triangle.

Comments
_Asif_ 27-Aug-14 5:13am
This is not a Pythagoras implementation. Pythagoras theorem is √(x^2+y^2 ). But the question is
-√(x^2 cos^2⁡ϑ+y^2) ̅

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 Richard Deeming 95 Andre Oosthuizen 80 Dave Kreskowiak 80 Maciej Los 45 Richard MacCutchan 30
 Richard MacCutchan 1,550 Dave Kreskowiak 1,540 Richard Deeming 893 Maciej Los 875 CPallini 860

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900