wasSharp – Diff between revs 14 and 27
?pathlinks?
Rev 14 | Rev 27 | |||
---|---|---|---|---|
Line 18... | Line 18... | |||
18 | |
18 | |
|
19 | public static Distance HaversineDistanceTo(this GeographicCoordinate sourceGeographicCoordinate, |
19 | public static Distance HaversineDistanceTo(this GeographicCoordinate sourceGeographicCoordinate, |
|
20 | GeographicCoordinate targetGeographicCoordinate, |
20 | GeographicCoordinate targetGeographicCoordinate, |
|
21 | DistanceUnits distanceUnits) |
21 | DistanceUnits distanceUnits) |
|
22 | { |
22 | { |
|
23 | var sourcePhi = Math.PI*sourceGeographicCoordinate.Latitude/180; |
23 | var sourcePhi = Math.PI * sourceGeographicCoordinate.Latitude / 180; |
|
24 | var targetPhi = Math.PI*targetGeographicCoordinate.Latitude/180; |
24 | var targetPhi = Math.PI * targetGeographicCoordinate.Latitude / 180; |
|
25 | var deltaPhi = Math.PI*(targetPhi - sourcePhi)/180; |
25 | var deltaPhi = Math.PI * (targetPhi - sourcePhi) / 180; |
|
Line -... | Line 26... | |||
- | 26 | var deltaLam = Math.PI * (targetGeographicCoordinate.Longitude - sourceGeographicCoordinate.Longitude) / 180; |
||
- | 27 | |
||
- | 28 | var a = Math.Sin(deltaPhi / 2) * Math.Sin(deltaPhi / 2) + |
||
Line 26... | Line 29... | |||
26 | var deltaLam = Math.PI*(targetGeographicCoordinate.Longitude - sourceGeographicCoordinate.Longitude)/180; |
29 | Math.Cos(sourcePhi) * Math.Cos(targetPhi) * |
|
27 | |
- | ||
28 | |
- | ||
Line 29... | Line -... | |||
29 | var a = Math.Sin(deltaPhi/2)*Math.Sin(deltaPhi/2) + |
- | ||
30 | Math.Cos(sourcePhi)*Math.Cos(targetPhi)* |
- | ||
31 | Math.Sin(deltaLam/2)*Math.Sin(deltaLam/2); |
30 | Math.Sin(deltaLam / 2) * Math.Sin(deltaLam / 2); |
|
32 | |
31 | |
|
33 | var c = 2*Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); |
32 | var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); |
|
34 | |
- | ||
35 | return new Distance(Constants.EARTH_MEAN_RADIUS.Meters*c); |
33 | |
|
- | 34 | return new Distance(Constants.EARTH_MEAN_RADIUS.Meters * c); |