1. GtkGreatCircle.ex
- Posted by Senator Aug 09, 2018
- 1168 views
-- -- GtkEarthDistance.ex -- include std/math.e include GtkEngine.e global function Great_Circle_Distance(atom LA1,atom LO1,atom LA2,atom LO2, integer miles = 1) -- given starting and destination latitude and longitude coordinates in degrees -- returns distance between the two points (default: miles = 1) or km (miles = 0) -- uses spherical law of cosines atom D, DLO=deg2rad(LO2-LO1), R=6371.02 -- mean earth radius in km LA1=deg2rad(LA1) LO1=deg2rad(LO1) LA2=deg2rad(LA2) LO2=deg2rad(LO2) D = arccos( sin(LA1) * sin(LA2) + cos(LA1) * cos(LA2) * cos(DLO)) * R if miles then D/= 1.609 end if return D end function constant units = {"miles", "km" }, CITY = 1, LA = 2, LO = 3, LALO={{"Wellington AU", 41.3, 174.7}, {"Auckland AU", 37.0, 174.7},{"Sydney AU", 33.7, 151.3}, {"Lyons GA USA", 32.2, 82.3},{"Tacoma, WA USA", 47.3, 122.5}, {"New York, NY USA", 40.7, 74.0}, {"Seattle, WA USA", 47.6, 122.3},{"Macon, GA USA", 32.8, 83.6},{"Vidalia, GA USA", 32.2, 82.4}, {"Atlanta GA USA", 33.8, 84.4},{"London UK", 51.5, 0.1}, {"Los Angeles, CA USA", 32.1, 18.2}} object cities = {} for i = 1 to length(LALO) do cities=append(cities,LALO[i][CITY]) end for constant win=create(GtkWindow,"title=Distance Between Cities,border_width=10,position=1,$destroy=Quit"), panel=create(GtkBox, "orientation=HORIZONTAL,spacing=10"), cb1=create(GtkComboBoxText, "tooltip text=Select Starting Location\nSelect OK button to update"), cb2=create(GtkComboBoxText, "tooltip text=Select Ending Location\nSelect OK button to update"), cb3=create(GtkComboBoxText, "tooltip text=Select Unit of Measure, $changed=CalcDist"), Dist=create(GtkEntry,"width chars=20, placeholder text=Distance"), btnbox=create(GtkButtonBox,"spacing=5"), btn1=create(GtkButton,"gtk-ok","CalcDist"), btn2=create(GtkButton,"gtk-quit","Quit") add(win,panel) add(panel,{cb1,cb2,cb3, Dist}) pack_end(panel,btnbox) add(btnbox,{btn1, btn2}) set(cb1, "text active") set(cb2, "text active") set(cb3,"text active") for i = 1 to length(cities) do set(cb1,"append text",cities[i]) set(cb2,"append text",cities[i]) end for for i = 1 to length(units) do set(cb3, "append text", units[i]) end for show_all(win) main() global function CalcDist() integer f=get(cb1,"active"),t=get(cb2,"active"),u=get(cb3,"active") sequence um ="" -- unit of measure if u = 1 then um="miles" else um="km" u=0 end if atom D = Great_Circle_Distance(LALO[f][LA],LALO[f][LO],LALO[t][LA], LALO[t][LO],u) object DD={D} DD=append(DD, sprintf("%s", {um})) set(Dist,"text", text:format("[.3] []", DD) ) return 1 end function
2. Re: GtkGreatCircle.ex
- Posted by irv Aug 09, 2018
- 1116 views
Nice, but there's a discrepancy - the program reports LAX to ATL to be 3771 miles, while iflightplanner claims 1686 nm or about 1940 statute miles.
3. Re: GtkGreatCircle.ex
- Posted by Senator Aug 09, 2018
- 1098 views
irv said...
Nice, but there's a discrepancy - the program reports LAX to ATL to be 3771 miles, while iflightplanner claims 1686 nm or about 1940 statute miles.
-- quick fix replace the Los Angeles LALO sequence with: {"Los Angeles, CA USA", 34.0522, 118.2437} -- renders 1931.788 miles or 1679 nmi from Atlanta to Los Angeles. -- I will recheck all LALO sequences and update the LALO sequence if needed -- perhaps I should use nautical miles instead of miles in the routine