Skip to content

Instantly share code, notes, and snippets.

@sean2121
Created February 19, 2018 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sean2121/505f387268f619c7ed8f3585457c0e83 to your computer and use it in GitHub Desktop.
Save sean2121/505f387268f619c7ed8f3585457c0e83 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<math.h>
float distance(double, double, double, double);
int main(void)
{
//点P
double latitude_s = 35.658581;
double longitude_s = 139.745433;
//点Q
double latitude_e = 43.062562;
double longitude_e = 141.353650;
double p2q = distance(latitude_s , longitude_s, latitude_e, longitude_e);
printf("%f\n", p2q);
return 0;
}
float distance(double latitude_s, double longitude_s, double latitude_e, double longitude_e)
{
double sin_lat_1 = sin(latitude_e * M_PI / 180);
double cos_lat_1 = cos(latitude_e * M_PI / 180);
double sin_lat_2 = sin(latitude_s * M_PI / 180);
double cos_lat_2 = cos(latitude_s * M_PI / 180);
double lamda1 = longitude_e * M_PI / 180;
double lamda2 = longitude_s * M_PI / 180;
double two_points_distance = 6370 * acos(sin_lat_1 * sin_lat_2 + cos_lat_1 * cos_lat_2 *
cos(lamda1 - lamda2));
return two_points_distance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment