add direction on matching wpts

This commit is contained in:
afischerdev 2023-02-26 12:36:56 +01:00
parent b735cd3e4e
commit 16a5ebe737
2 changed files with 117 additions and 6 deletions

View file

@ -46,4 +46,30 @@ public final class CheapAngleMeter {
}
return offset + sinp * (57.4539 + s2 * (9.57565 + s2 * (4.30904 + s2 * 2.56491)));
}
public static double getAngle(int lon1, int lat1, int lon2, int lat2) {
double res = 0;
double xdiff = lat2 - lat1;
double ydiff = lon2 - lon1;
res = Math.toDegrees(Math.atan2(ydiff, xdiff));
return res;
}
public static double getDirection(int lon1, int lat1, int lon2, int lat2) {
double res = getAngle(lon1, lat1, lon2, lat2);
return normalize(res);
}
public static double normalize(double a) {
return a >= 360 ? a - (360 * (int) (a / 360))
: a < 0 ? a - (360 * ((int) (a / 360) - 1)) : a;
}
public static double getDifferenceFromDirection(double b1, double b2) {
double r = (b2 - b1) % 360.0;
if (r < -180.0) r += 360.0;
if (r >= 180.0) r -= 360.0;
return Math.abs(r);
}
}