//public static double GetRadius(double latitude, double radius = GeoGlobal.Earths.RadiusEquatorial) //{ // latitude = latitude.ToRadians(); // var a = GeoGlobal.Earths.RadiusEquatorial; // var b = GeoGlobal.Earths.RadiusPolar; // var e = Math.Pow(b*b/a*a, 1/2); // return a * (1.0 - e * e) / (1.0 - e * 2 * Math.Sin ^ 2(latitude)) ^ (3 / 2); //} #endregion #region Geographic Path /// <summary> /// Calculates geographic path between two geographic locations on the Great Circle /// <para>Using the Spherical law of cosines </para> /// </summary> /// <param name="origin">origin location in geographic degrees</param> /// <param name="destination">destination location in geographic degrees</param> /// <param name="interval">interval between consecutive points of the geographic path, in kilometers</param> /// <param name="radius">radius of a geographic sphere, in kilometers</param> public static GeoPointList GetPathPoints(IGeoLocatable origin, IGeoLocatable destination, double interval = GeoGlobal.Earths.CircumferenceOneDegree, double radius = GeoGlobal.Earths.Radius) { var path = new GeoPointList(); var distance = GeoCalculator.GetDistance(origin, destination); if (double.IsNaN(distance.Kilometers)) { return(path); } if (distance.Kilometers <= interval) { path.Add(origin.ToGeoPoint()); path.Add(destination.ToGeoPoint()); } else { var currentPoint = origin.ToGeoPoint(); for (double dist = interval; dist <= distance.Kilometers; dist += interval) { path.Add(currentPoint); var bearing = GeoCalculator.GetBearing(currentPoint, destination); currentPoint = GeoCalculator.GetDestination(currentPoint, bearing, interval); } path.Add(destination.ToGeoPoint()); } return(path); }
/// <summary> /// Calculates geographic path between two geographic locations on the Great Circle /// <para>Using the Spherical law of cosines </para> /// </summary> /// <param name="geoShape">list of points in geographic shape</param> /// <param name="interval">interval between consecutive points of the geographic path, in kilometers</param> /// <param name="radius">radius of a geographic sphere, in kilometers</param> public static GeoPointList GetPathPoints(IEnumerable <IGeoLocatable> geoShape, double interval = GeoGlobal.Earths.CircumferenceOneDegree, double radius = GeoGlobal.Earths.Radius) { var path = new GeoPointList(); if (geoShape.Count() <= 2) { path.AddRange(geoShape.Select(point => point.ToGeoPoint())); } else // if (geoShapePoints.Count > 2) { var currentPoint = geoShape.First().ToGeoPoint(); for (int i = 1; i < geoShape.Count(); i++) { var nextPoint = geoShape.ElementAt(i).ToGeoPoint(); var points = GetPathPoints(currentPoint, nextPoint, interval, radius); path.AddRange(points); currentPoint = nextPoint; } } return(path); }