wasSharp – Blame information for rev 27
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
14 | office | 1 | /////////////////////////////////////////////////////////////////////////// |
2 | // Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 // |
||
3 | // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // |
||
4 | // rights of fair usage, the disclaimer and warranty conditions. // |
||
5 | /////////////////////////////////////////////////////////////////////////// |
||
6 | |||
7 | using System; |
||
8 | |||
9 | namespace wasSharp.Geo |
||
10 | { |
||
11 | public static class GeodesicExtensions |
||
12 | { |
||
13 | public static Distance HaversineDistanceTo(this GeographicCoordinate sourceGeographicCoordinate, |
||
14 | GeographicCoordinate targetGeographicCoordinate) |
||
15 | { |
||
16 | return HaversineDistanceTo(sourceGeographicCoordinate, targetGeographicCoordinate, DistanceUnits.KILOMETERS); |
||
17 | } |
||
18 | |||
19 | public static Distance HaversineDistanceTo(this GeographicCoordinate sourceGeographicCoordinate, |
||
20 | GeographicCoordinate targetGeographicCoordinate, |
||
21 | DistanceUnits distanceUnits) |
||
22 | { |
||
27 | office | 23 | var sourcePhi = Math.PI * sourceGeographicCoordinate.Latitude / 180; |
24 | var targetPhi = Math.PI * targetGeographicCoordinate.Latitude / 180; |
||
25 | var deltaPhi = Math.PI * (targetPhi - sourcePhi) / 180; |
||
26 | var deltaLam = Math.PI * (targetGeographicCoordinate.Longitude - sourceGeographicCoordinate.Longitude) / 180; |
||
14 | office | 27 | |
27 | office | 28 | var a = Math.Sin(deltaPhi / 2) * Math.Sin(deltaPhi / 2) + |
29 | Math.Cos(sourcePhi) * Math.Cos(targetPhi) * |
||
30 | Math.Sin(deltaLam / 2) * Math.Sin(deltaLam / 2); |
||
14 | office | 31 | |
27 | office | 32 | var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); |
14 | office | 33 | |
27 | office | 34 | return new Distance(Constants.EARTH_MEAN_RADIUS.Meters * c); |
14 | office | 35 | } |
36 | } |
||
27 | office | 37 | } |