Skip to content

Instantly share code, notes, and snippets.

@ghelobytes
Created June 10, 2014 03:56
Show Gist options
  • Save ghelobytes/d2515a9b82748f8020b5 to your computer and use it in GitHub Desktop.
Save ghelobytes/d2515a9b82748f8020b5 to your computer and use it in GitHub Desktop.
Calculate Next point based on current point, heading, bearing, DMS and distance
private double[] NextPoint(double startX, double startY, string heading, string bearing, int degree, int minute, double seconds, double distance)
{
double DEG2RAD = 4 * Math.Atan(1) / 180;
double azimuth = degree + (minute / 60);
string hb = heading + bearing;
switch (hb.ToUpper())
{
case "NE":
// do nothing
break;
case "NW":
azimuth = 0 - azimuth;
break;
case "SE":
azimuth = 180 - azimuth;
break;
case "SW":
azimuth = -180 + azimuth;
break;
default:
azimuth = 0;
break;
}
azimuth = azimuth * DEG2RAD;
double endX = startX + Math.Sin(azimuth) * distance;
double endY = startY + Math.Cos(azimuth) * distance;
return new double[] { endX, endY };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment