Advertisement
KDuarte

ISTO

Apr 20th, 2013
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. float haversine_km(float lat1, float long1, float lat2, float long2){
  2.     float dlong = (long2 - long1) * d2r;
  3.     float dlat = (lat2 - lat1) * d2r;
  4.     float a = pow(sin(dlat/2.0), 2) + cos(lat1*d2r) * cos(lat2*d2r) * pow(sin(dlong/2.0), 2);
  5.     float c = 2 * atan2(sqrt(a), sqrt(1-a));
  6.     float d = 6367 * c;
  7.     return d;
  8. }
  9.  
  10. void insertionSort(struct novasrotas array_rotas[], int tam)
  11. {
  12.         int i, j;
  13.         struct novasrotas aux;
  14.         for(i = 1; i < tam; i++){
  15.                 j = i;
  16.                 while((j != 0) && (haversine_km(array_rotas[j].latitude, array_rotas[j].longitude, 38.750, -9.110) < haversine_km(array_rotas[j-1].latitude, array_rotas[j-1].longitude, 38.750, -9.110))) {
  17.                         aux = array_rotas[j];
  18.                         array_rotas[j] = array_rotas[j-1];
  19.                         array_rotas[j-1] = aux;
  20.                         j--;
  21.                 }
  22.         }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement