#include #include #include #include #include #include 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; }