40 lines
1.2 KiB
Text
40 lines
1.2 KiB
Text
/* fórmula de Haversine para distancias en una
|
|
superficie esférica */
|
|
|
|
#include <basico.h>
|
|
|
|
#define MIN 60
|
|
#define SEG 3600
|
|
#define RADIO 6372.8
|
|
#define UNAMILLA 1.609344
|
|
|
|
algoritmo
|
|
|
|
números ( lat1, lon1, lat2, lon2, dlat, dlon, millas )
|
|
|
|
si ' total argumentos es (9) ' // LAT1 M LON1 M LAT2 M LON2 M
|
|
#basic{ lat1 = narg(2) + narg(3)/MIN
|
|
lon1 = narg(4) + narg(5)/MIN
|
|
lat2 = narg(6) + narg(7)/MIN
|
|
lon2 = narg(8) + narg(9)/MIN }
|
|
|
|
sino si ' total argumentos es (13) ' // LAT1 M LON1 M S LAT2 M LON2 M S
|
|
#basic{ lat1 = narg(2) + narg(3)/MIN + narg(4)/SEG
|
|
lon1 = narg(5) + narg(6)/MIN + narg(7)/SEG
|
|
lat2 = narg(8) + narg(9)/MIN + narg(10)/SEG
|
|
lon2 = narg(11) + narg(12)/MIN + narg(13)/SEG }
|
|
sino
|
|
imprimir("Modo de uso:\ndist.bas La1 M [S] Lo1 M [S] La2 M [S] Lo2 M [S]\n")
|
|
término prematuro
|
|
fin si
|
|
|
|
#basic{
|
|
dlat = sin(radian(lat2 - lat1)/2)^2
|
|
dlon = sin(radian(lon2 - lon1)/2)^2
|
|
RADIO*(2*arc sin(sqrt(dlat + cos(radian(lat1)) * cos(radian(lat2)) * dlon )))
|
|
}
|
|
|
|
---copiar en 'millas'---, " km. (",millas,dividido por (UNA MILLA)," mi.)\n"
|
|
decimales '2', imprimir
|
|
|
|
terminar
|