Distances and directions on the earth's surface
Distances and directions on the earth's surface
Source: http://newsgroups.derkeiler.com/Archive/Comp/comp.sys.hp48/2007−04/msg00524.html
• From: Scott Hemphill
• Date: 23 Apr 2007 11:12:04 −0400
I wrote this program and placed it in the public domain.
Scott Hemphill 23 April 2007
There is no warranty expressed or implied on this software. It's not
mine, anyway. It's yours!
Distances and directions on the earth's surface
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
This program is called GEOD. It gives distances and directions along
the earth's surface by calculating geodesics on the WGS−84 ellipsoid.
Input:
−−−−−−
latitude of point A (north is positive, south is negative)
longitude of point A (east is positive, west is negative)
latitude of point B
longitude of point B
Output:
−−−−−−−
distance between point A and point B in nautical miles
true course in degrees between A and B as departing point A
true course in degrees between A and B as arriving at point B
(If a course is less than zero degrees, add 360 degrees to it. The
reason that GEOD doesn't do it is that on my calculator, this is a
lower level program that is called by other programs, and adding 360
degrees here would be a waste of time.)
I think I wrote this program over ten years ago for my HP−48SX. My
documentation for it isn't handy, so it's pretty much a black box,
even to me. There are some pathological cases which are not handled
well by the algorithm: two points on opposite sides of the earth, and
any two points on the equator. I would expect that inputs that are
close to these pathological cases will also suffer significantly
reduced accuracy. The results of this program have always agreed with
every distance I have compared with on aeronautical charts, even on
Distances and directions on the earth's surface 1
Distances and directions on the earth's surface
courses over 1000 nautical miles. Aeronautical charts typically give
distances rounded to the nearest nautical mile. Instrument approach
charts give distances to tenths of nautical miles, and I have yet to
see a discrepancy for those either.
This is a transcription by hand of the program as it currently exists
on my HP−48GX calculator. I was careful, and used the transcription
to re−enter the program onto the calculator to check my work.
\C LN IM DUP 7
DUPN
DO 7 DROPN 0 OVER
R\−>C EXP C−>R OVER 6
PICK * 9 PICK + 3
PICK 9 PICK * 8
PICK − SQ 3 PICK 12
PICK * SQ + \v/ DUP2
R\−>C LN IM 4 PICK 9
PICK * 3 PICK / DUP
SQ 1 − NEG
IF DUP
THEN 13 PICK
OVER / 2 * 6 PICK −
NEG
END OVER DUP −3
*4+
3.35281066474E−3 *
4+*
3.35281066474E−3 *
16 / OVER SQ 2 * 1
− 8 PICK * OVER * 3
PICK + 7 PICK *
OVER * 6 PICK + 5
ROLL *
3.35281066474E−3 *
SWAP 1 − NEG * 10
PICK + DUP 10 ROLLD
9 ROLL −
UNTIL ABS
..0000000001 C ARG 6 ROLL NEG
6 ROLL 6 ROLL * + 5
ROLL 5 ROLL * R\−>C
ARG
\>>
BYTES gives:
#17944d (or #4618h)
1016
Examples:
Input:
45 45 degrees north latitude
0 0 degrees longitude
45 45 degrees north latitude
90 90 degrees east longitude
Output:
3612.43678893 distance in nautical miles
54.7260972283 initial true course in degrees
125.273902772 final true course in degrees
Input:
42.3643475 latitude and longitude of the airport reference point
−71.0051791667 for Logan Airport in Boston, Massachusetts
40.6397511111 latitude and longitude of the airport reference point
−73.7789255556 for Kennedy Airport in New York City, New York
Output:
162.25971407 distance is approximately 162.3 nautical miles
Distances and directions on the earth's surface 3
Distances and directions on the earth's surface
−128.667216234 initial true course is approximately 360−129 = 231 degrees
−130.505641309 final true course is approximately 360−131 = 229 degrees
Scott
−−
Scott Hemphill hemphill@xxxxxxxxxxxxxxxxxx
"This isn't flying. This is falling, with style." −− Buzz Lightyear
.
Distances and directions on the earth's surface 4