Great Circle calculates the shortest distance between two geographic points on Earth’s surface using spherical trigonometry. The program accepts departure and destination coordinates in degrees, minutes, and seconds, with negative values indicating east longitude or south latitude. It applies the spherical law of cosines via the arc-cosine function (ACS) to compute the central angle, then converts the result to both nautical miles and statute miles. The constant 108,000/π maps the arc-cosine result (in radians) to nautical miles at a resolution of tenths, with INT used to round the result. Output is formatted using PRINT AT for screen placement, and a PRINT #1 statement targets the lower portion of the display for the continue prompt.
Program Structure
The program is organized as a main loop with a clear subroutine hierarchy. The main flow (lines 10–210) collects two coordinate pairs, computes the great-circle distance, displays results, and loops back. Three subroutines handle input abstraction:
GO SUB 220— collects a latitude in DMS format, storing the decimal-degree result inLATGO SUB 260— collects a longitude in DMS format, storing the result inLONGGO SUB 300— the shared inner routine that prompts for and reads degrees, minutes, and seconds intoDEG,MIN, andSEC
The latitude and longitude subroutines are nearly identical in structure, differing only in their PRINT label and target variable. Both call the common DMS-input subroutine at line 300, which prints each entered value back to the screen after INPUT for confirmation.
Mathematical Method
The program uses the spherical law of cosines to compute angular distance. The core formula appears at lines 150–170:
- Line 150: computes the difference in longitudes
Din radians:(LONG1-LONG2)*PI/180 - Line 160: evaluates
Z = sin(lat1)·sin(lat2) + cos(lat1)·cos(lat2)·cos(ΔL), the cosine of the central angle - Line 170: applies
ACS Z(arc-cosine) to recover the central angle, then scales by108000/PIto convert radians to tenths of nautical miles
The scaling factor 108,000/π derives from the fact that 1 nautical mile subtends 1 arcminute of arc, and there are 10,800 arcminutes in π radians; multiplying by 10 gives tenths of nautical miles, allowing DIST/10 to display one decimal place. The statute mile conversion at line 190 uses the factor 0.115, which is the product of the 1/10 scaling and the nautical-to-statute ratio (approximately 1.15).
Coordinate Input Convention
The REM at line 40 documents the sign convention: east longitudes and south latitudes are entered as negative numbers. This is the opposite of the more common convention where east and north are positive, but it is mathematically consistent because the formula uses only the cosine of the longitude difference, which is an even function — so the sign of the individual longitudes does not affect the distance result, only their difference matters. South latitudes as negatives is standard and works correctly with the sine and cosine terms.
Key BASIC Idioms
PRINT AT 10,0;on line 180 positions the distance output at a specific screen row, separating results visually from the input prompts above.- Line 200 uses
PRINT #1; AT 0,0;to write the continue prompt to stream 1 (the lower display area), keeping it separate from the main screen output. - The keypress wait on line 200 uses the idiom
IF INKEY$="" THEN GO TO 200, polling until any key is pressed before clearing and restarting. INT(.5 + …)on line 170 performs rounding to the nearest integer rather than truncation.- Variables
DEG,MIN, andSECare reused for both latitude and longitude input, relying on the subroutine call sequence to assign them before use — a typical memory-saving pattern.
Potential Anomalies
Line 160 parses as Z = SIN(LAT1) * SIN(LAT2) + (COS(LAT1) * COS(LAT2) * COS(D)), which is the correct spherical law of cosines. No parentheses are written around the SIN and COS arguments because BASIC’s function syntax does not require them for single-variable expressions.
The longitude difference on line 150 is computed as LONG1 - LONG2 before converting to radians, but LONG1 and LONG2 are stored in decimal degrees (not radians), so the multiplication by PI/180 is correctly applied to the difference. Note that LAT1 and LAT2 are converted to radians at lines 60 and 110 before storage, but LONG1 and LONG2 are stored in decimal degrees — the radians conversion for longitude happens only at line 150. This asymmetry is intentional and correct.
The statute mile factor 0.115 on line 190 is applied to DIST, which is already in tenths of nautical miles. Since 1 nautical mile = 1.15078 statute miles, dividing DIST by 10 and multiplying by 1.15 is equivalent to multiplying DIST by 0.115 — the arithmetic is correct.
Variable Summary
| Variable | Purpose |
|---|---|
LAT | Decimal-degree latitude from subroutine |
LAT1, LAT2 | Departure and destination latitudes in radians |
LONG | Decimal-degree longitude from subroutine |
LONG1, LONG2 | Departure and destination longitudes in decimal degrees |
D | Longitude difference in radians |
Z | Cosine of the central angle |
DIST | Distance in tenths of nautical miles (integer) |
DEG, MIN, SEC | Reusable DMS input components |
Content
Source Code
10 CLS
20 REM "GREAT CIRCLE"
30 PRINT "DEPARTURE POINT"
40 REM When you enter alongitude east of Greenwich or alatitude south of the equator, use negative numbers.
50 GO SUB 220
60 LET LAT1=LAT* PI/180
70 GO SUB 260
80 LET LONG1=LONG
90 PRINT "DESTINATION"
100 GO SUB 220
110 LET LAT2=LAT* PI/180
120 GO SUB 260
130 LET LONG2=LONG
140 CLS
150 LET D=(LONG1-LONG2)* PI/180
160 LET Z= SIN LAT1* SIN LAT2+(COS LAT1* COS LAT2* COS D)
170 LET DIST= INT (.5+(108000/ PI* ACS Z))
180 PRINT AT 10,0;"DISTANCE NAUTICAL MILES = ";DIST/10
190 PRINT "STATUTE MILES = ";.115*DIST
200 PRINT #1; AT 0,0;"TO CONTINUE PRESS ENTER":IF INKEY$="" THEN GO TO 200
210 CLS :GO TO 10
220 PRINT "LATITUDE"
230 GO SUB 300
240 LET LAT=DEG+MIN/60+SEC/3600
250 RETURN
260 PRINT "LONGITUDE"
270 GO SUB 300
280 LET LONG=DEG+MIN/60+SEC/3600
290 RETURN
300 PRINT "INPUT DEGREES ";
310 INPUT DEG
320 PRINT DEG
330 PRINT "INPUT MINUTES ";
340 INPUT MIN
350 PRINT MIN
360 PRINT "INPUT SECONDS ";
370 INPUT SEC
380 PRINT SEC
390 PRINT
400 RETURN
410 SAVE "GrtCircle" LINE 1
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
