Last active
April 20, 2021 14:20
-
-
Save balamuruganky/7699d07dadb275d4928f25e81a7691bc to your computer and use it in GitHub Desktop.
Revisions
-
balamuruganky revised this gist
Apr 20, 2021 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -35,9 +35,9 @@ int main(int argc, char** argv) { printf ("%2.7f, %2.7f, %f\n", newLatitude, newLongitude, currentDirection); //Update old Latitude and Longitude oldLatitude = newLatitude; oldLongitude = newLongitude; } return 0; -
balamuruganky created this gist
Apr 20, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ #include <stdio.h> #include <math.h> #include <time.h> #include <iostream> #include <string> #include <iomanip> using namespace std; int main(int argc, char** argv) { constexpr double earthRadius = 6371000.0; double oldLatitude = 52.0; double oldLongitude = -2.0; double currentDirection = 360.0; double currentDistanceTravelled = 0.001; for (int i = 1; i <= 360; i++) { currentDirection = 90; currentDistanceTravelled += 0.001; // Convert Variables to Radian for the Formula oldLatitude = M_PI * oldLatitude / 180.0; oldLongitude = M_PI * oldLongitude / 180.0; currentDirection = (double) (M_PI * currentDirection / 180.0); // Formulae to Calculate the NewLAtitude and NewLongtiude double newLatitude = asin(sin(oldLatitude) * cos(currentDistanceTravelled / earthRadius) + cos(oldLatitude) * sin(currentDistanceTravelled / earthRadius) * cos(currentDirection)); double newLongitude = oldLongitude + atan2(sin(currentDirection) * sin(currentDistanceTravelled / earthRadius) * cos(oldLatitude), cos(currentDistanceTravelled / earthRadius) - sin(oldLatitude) * sin(newLatitude)); // Convert Back from radians newLatitude = 180.0 * newLatitude / M_PI; newLongitude = 180.0 * newLongitude / M_PI; currentDirection = (double) (180.0 * currentDirection / M_PI); printf ("%2.7f, %2.7f, %f\n", newLatitude, newLongitude, currentDirection); //Update old Latitude and Longitude oldLatitude = newLatitude; oldLongitude = newLongitude; } return 0; }