Skip to content

Commit

Permalink
Merge pull request #31 from CSE-110-Winter-2023/MS1-Demo
Browse files Browse the repository at this point in the history
Fixed angle calculation
  • Loading branch information
vs2961 committed Mar 1, 2023
2 parents 10aee99 + 6095ae2 commit f1130cc
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions app/src/main/java/utilities/Calculation.java
Expand Up @@ -6,19 +6,12 @@ public static float getCompassRotation(float deviceOrientation) {
}

public static float getAngle(double lat1, double long1, double lat2, double long2) {
lat1 = Math.toRadians(lat1);
long1 = Math.toRadians(long1);
lat2 = Math.toRadians(lat2);
long2 = Math.toRadians(long2);
double dLat = lat2 - lat1;
double dLng = long1 - long2;

double dLong = (long2 - long1);
double radsFromX = Math.atan2(dLat, dLng);
double degsFromN = Math.toDegrees(radsFromX) - 90;

double y = Math.sin(dLong) * Math.cos(lat2);
double x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLong);
double angle = Math.atan2(y, x);

return (float) (Math.toDegrees(angle) + 360) % 360;
return (float) degsFromN;
}


}

0 comments on commit f1130cc

Please sign in to comment.