Created
January 28, 2010 17:14
-
-
Save anonymous/288936 to your computer and use it in GitHub Desktop.
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 characters
#include <math.h> | |
#include <sys/time.h> | |
#include <stdio.h> | |
double clock() { | |
struct timeval tv; | |
gettimeofday(&tv,NULL); | |
return tv.tv_sec + 1e-6*tv.tv_usec; | |
} | |
static inline double sqr(double x) {return x*x;} | |
static double radians(double deg) {return deg * M_PI / 180;} | |
static double distance(double latA,double lngA,double latB,double lngB) { | |
double | |
radius = 6371, | |
latAr = radians(latA), | |
lngAr = radians(lngA), | |
latBr = radians(latB), | |
lngBr = radians(lngB), | |
deltaLat = latBr - latAr, | |
deltaLng = lngBr - lngAr; | |
return radius * 2 * asin(sqrt(sqr(sin(deltaLat/2)) | |
+ cos(latAr) * cos(latBr) * sqr(sin(deltaLng/2)))); | |
} | |
int main(void) { | |
int i,j,k,l; | |
double start,total = 0; | |
start = clock(); | |
for (i=0; i<73; i++) | |
for (j=0; j<145; j++) | |
for (k=0; k<73; k++) | |
for (l=0; l<145; l++) | |
total += distance(-90+2.5*i,-180+2.5*j,-90+2.5*k,-180+2.5*l); | |
printf("total = %g, time = %g\n",total,clock()-start); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment