Closed GoogleCodeExporter closed 8 years ago
Hey, thanks a lot for this, looks great - I am planning to commit a new version
real soon and I am pretty sure I'll pop this in. Although the logic will go in
the Geo.Maths class as a static method, I will add a method with the same
signature as yours to the Coordinate class.
// Maths.cs
public static double[] Destination(Coordinate origin, double distance, double
bearing, bool kilometers = true)
{
double lat1 = Maths.ConvertDegreesToRadians(origin.Latitude);
double lon1 = Maths.ConvertDegreesToRadians(origin.Longitude);
bearing = Maths.ConvertDegreesToRadians(bearing);
double angularDistance = 0;
if (kilometers)
{
angularDistance = distance / Maths.EarthMeanRadiusKilometres;
}
else
{
angularDistance = Maths.ConvertKilometresToMiles(distance) / Maths.EarthMeanRadiusMiles;
}
double lat2 = Math.Asin(Math.Sin(lat1) * Math.Cos(angularDistance) + Math.Cos(lat1) * Math.Sin(angularDistance) * Math.Cos(bearing));
double lon2 = lon1 + Math.Atan2(Math.Sin(bearing) * Math.Sin(angularDistance) * Math.Cos(lat1), Math.Cos(angularDistance) - Math.Sin(lat1) * Math.Sin(lat2));
return new double[] { Maths.ConvertRadiansToDegrees(lat2), Maths.ConvertRadiansToDegrees(lon2) };
}
public static double[] Destination(double[] origin, double distance, double
bearing, bool kilometers = true)
{
return Destination(new Coordinate(origin), distance, bearing, kilometers);
}
// Coordinate.cs
public Coordinate Destination(double distance, double bearing, bool kilometers
= true)
{
return new Coordinate(Maths.Destination(this, distance, bearing, kilometers));
}
Original comment by fraser.c...@gmail.com
on 24 Aug 2011 at 10:41
This has been added to the latest commit
Original comment by fraser.c...@gmail.com
on 8 Oct 2011 at 12:45
Original issue reported on code.google.com by
joe.wake...@gmail.com
on 22 Aug 2011 at 2:44