1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include "stdafx.h"
#include "math.h"
#define PI 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200
double deg2rad(double);
double rad2deg(double);
int main()
{
printf("Nautical Miles Distance Calculator\n");
// Variable Declaration
double Lat1, Long1, Lat2, Long2, Distance;
// Input
printf("Please enter the Latitude of the first point >");
scanf("%lf", &Lat1);
printf("Please enter Longitude of the second point >");
scanf("%lf", &Long1);
printf("Please enter Latitude of second point >");
scanf("%lf", &Lat2);
printf("Please enter Longitude of the second point >");
scanf("%lf", &Long2);
//Calculations
Distance = sin((deg2rad(Lat1)) * sin(deg2rad(Lat2)) + cos(deg2rad(Lat1)) * cos(deg2rad(Lat2)) * (cos(deg2rad(Long1) - deg2rad(Long2))));
Distance = acos(Distance);
Distance = rad2deg(Distance);
//Distance = Distance * 60;
//Distance = Distance * 1.609344;
//Distance = Distance * 0.8684;
//Output
printf("The nautical miles between point (%f,%f) and (%f,%f) is %f\n", Lat1, Long1, Lat2, Long2, Distance);
return 0;
}
double deg2rad(double deg) {
return (deg * PI / 180);
}
double rad2deg(double rad) {
return (rad * 180 / PI);
}
|