wasSharp – Blame information for rev 14

Subversion Repositories:
Rev:
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 {
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;
27  
28  
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);
32  
33 var c = 2*Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
34  
35 return new Distance(Constants.EARTH_MEAN_RADIUS.Meters*c);
36 }
37 }
38 }