RosettaCodeData/Task/Haversine-formula/Smart-BASIC/haversine-formula.basic
2023-07-01 13:44:08 -04:00

41 lines
1.1 KiB
Text

'*** LAT/LONG for Nashville International Airport (BNA)
lat1=36.12
Lon1=-86.67
'*** LAT/LONG for Los Angeles International Airport (LAX)
Lat2=33.94
Lon2=-118.40
'*** Units: K=kilometers M=miles N=nautical miles
Unit$ = "K"
Result=HAVERSINE(Lat1,Lon1,Lat2,Lon2,Unit$)
R$=STR$(Result,"#,###.##")
PRINT "The distance between Nashville International Airport and Los Angeles International Airport in kilometers is: "&R$
STOP
DEF HAVERSINE(Lat1,Lon1,Lat2,Lon2,Unit$)
'---------------------------------------------------------------
'*** Haversine Formula - Calculate distances by LAT/LONG
'
'*** Pass to it the LAT/LONG of the two locations, and then unit of measure
'*** Usage: X=HAVERSINE(Lat1,Lon1,Lat2,Lon2,Unit$)
PI=3.14159265358979323846
Radius=6372.8
Lat1=(Lat1*PI/180)
Lon1=(Lon1*PI/180)
Lat2=(Lat2*PI/180)
Lon2=(Lon2*PI/180)
DLon=Lon1-Lon2
Answer=ACOS(SIN(Lat1)*SIN(Lat2)+COS(Lat1)*COS(Lat2)*COS(DLon))*Radius
IF UNIT$="M" THEN Answer=Answer*0.621371192
IF UNIT$="N" THEN Answer=Answer*0.539956803
RETURN Answer
ENDDEF