public static IEnumerable <Point> GetPathPoints(PolyLine line, double speed, int period) { double stepDistance = speed / 1000d * period; var points = new List <Point>(); double currentRemainderOfDistance = 0d; Point current = null; Point previous = null; double bearing; for (int i = 1; i < line.Count; i++) { current = line[i]; previous = line[i - 1]; bearing = GeoHelper.GetBearing(previous, current); double lineDistance = previous.GetDistance(current); if (currentRemainderOfDistance > 0) { var firstPoint = GeoHelper.GetNextPoint(previous, bearing, stepDistance - currentRemainderOfDistance); points.Add(firstPoint); previous = firstPoint; lineDistance = lineDistance - (stepDistance - currentRemainderOfDistance); } while (lineDistance >= stepDistance) { var point = GeoHelper.GetNextPoint(previous, bearing, stepDistance); points.Add(point); lineDistance -= stepDistance; previous = point; } currentRemainderOfDistance = lineDistance; } if (currentRemainderOfDistance > 0) { points.Add(line.LatLongs.Last()); } return(points); }
public void TestNextPointAndDistanceCalculating() { Point a = new Point { Lat = 52.458393, Long = 31.025021 }; Point b = new Point { Lat = 52.459146, Long = 31.024851 }; double expectedDistance = 2; double bearing = GeoHelper.GetBearing(a, b); Point nextPoint = GeoHelper.GetNextPoint(a, bearing, expectedDistance); double distance = GeoHelper.GetDistance(a, nextPoint); Assert.AreEqual(expectedDistance, Math.Round(distance)); }