Trigonometry

This file is part of and Timex Sinclair Public Domain Library Tape 1006. Download the collection to get this file.
Date: 198x
Type: Program
Platform(s): TS 1000

This program is a trigonometry calculator covering all nine fundamental right-triangle formulae using sine, cosine, and tangent. A menu screen (lines 10–150) displays all nine formula options (A through I) alongside ASCII block-graphic representations of a right triangle drawn with the ▙ character, with option J providing a STOP. Each chosen formula branches to a dedicated input-and-calculation routine that prompts the user for the required known values, converts degrees to radians using the PI constant where needed, applies the appropriate trig function or its inverse (ASN, ACS, ATN), and displays the result before looping back to the menu. The degree/radian conversion pattern `S*PI/180` and its inverse `*180/PI` appears consistently throughout all nine calculation blocks.


Program Analysis

Program Structure

The program is divided into three logical zones:

  1. Menu display (lines 10–150): Clears the screen and prints the formula menu with block-graphic triangle diagrams and labelled options A–J.
  2. Input dispatcher (lines 800–910): Reads a single character into B$ and branches to the appropriate calculation routine, or STOPs on “J”. Line 910 re-prompts on any out-of-range character.
  3. Calculation routines (lines 1100–2810): Nine self-contained blocks, each CLS-ing, prompting for two known values, computing the unknown, displaying the result, waiting for NEWLINE, then GOTO 10 to return to the menu.

Lines 2820–2840 form a save/run footer: CLEAR, SAVE "1025%7" (the %7 being an inverse “7” triggering auto-run), followed by RUN.

Formula Coverage

OptionFormulaUnknowns SoughtKey Operation
ASIN = OPP/HYPAngle (degrees)ASN(O/H)*180/PI
BOPP = SIN*HYPOPPSIN(S*PI/180)*H
CHYP = OPP/SINHYPO/SIN(S*PI/180)
DCOS = ADJ/HYPAngle (degrees)ACS(A/H)*180/PI
EADJ = COS*HYPADJCOS(C*PI/180)*H
FHYP = ADJ/COSHYPA/COS(C*PI/180)
GTAN = OPP/ADJAngle (degrees)ATN(O/A)*180/PI
HOPP = TAN*ADJOPPTAN(T*PI/180)*A
IADJ = OPP/TANADJO/TAN(T*PI/180)

Degree/Radian Conversion

All forward trig calls (options B, C, E, F, H, I) require the user to enter an angle in degrees. The program consistently converts with S*PI/180 (or C*PI/180, T*PI/180) before passing to SIN, COS, or TAN. Inverse results from ASN, ACS, and ATN (options A, D, G) are converted back to degrees with *180/PI. This is correct and consistent throughout.

Notable Techniques

  • Block-graphic triangle diagrams: The menu uses the \.:` escape (▙) repeated to sketch right-triangle silhouettes, labelling hypotenuse, opposite, adjacent, and the relevant trig ratio direction inline within PRINT statements.

  • Inverse video label: Line 140 prints %S%T%O%P (inverse-video “STOP”) for option J, making it visually distinct from the formula labels.

  • Single-character dispatch: The dispatcher at lines 810–900 uses nine sequential IF … THEN GOTO lines rather than computed GOTO, which is typical of Sinclair BASIC where ON … GOTO is not available.

  • “Press NEWLINE to continue” idiom: Each calculation block uses INPUT A$ (line x10) solely as a pause mechanism, accepting any input — a common Sinclair BASIC substitute for a dedicated key-wait.

  • Variable reuse: A$ is used as the “press NEWLINE” sink in every calculation block (lines 1210, 1400, 1600, etc.), while B$ is reserved for the menu selection. Numeric variables are reused across routines without issue because each block reassigns before use.

Bugs and Anomalies

  • Misleading prompts for forward trig inputs: In routines B, C, E, F, H, and I, the echo line prints e.g. "SIN= ";S;" DEGS" (line 1330), but SIN, COS, and TAN are dimensionless ratios — the user is entering an angle in degrees, not a ratio. The label " DEGS" is technically correct for the angle, but the variable name S (named after SIN) and the prompt "INPUT SIN" are potentially confusing.
  • No input validation: There is no guard against division by zero (e.g., entering HYP=0 for option A, or ADJ=0 for option G), which would cause a runtime error.
  • Line 910 range check: IF B$<"A" OR B$>"J" THEN GOTO 800 correctly rejects characters outside A–J but does not handle the letters K–Z entered as lower-case or multi-character strings, since the earlier checks only test exact uppercase equality. Lower-case entries would fall through to line 910 and re-prompt correctly.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10252 – 10293.

Related Products

Related Articles

Related Content

Image Gallery

Trigonometry

Source Code

  10 CLS 
  20 PRINT AT 1,8;"**TRIGONOMETRY**"
  30 PRINT AT 4,0;"INPUT";TAB 8;"FORMULAE"
  40 PRINT AT 6,2;"A";TAB 7;"SIN=OPP/HYP";TAB 27;"\.:"
  50 PRINT AT 7,2;"B";TAB 7;"OPP=SIN*HYP";TAB 22;"HYP \.:%  OPP"
  60 PRINT AT 8,2;"C";TAB 7;"HYP=OPP/SIN  SIN->\.:% % "
  70 PRINT AT 10,2;"D";TAB 7;"COS=ADJ/HYP";TAB 27;"\.:"
  80 PRINT AT 11,2;"E";TAB 7;"ADJ=COS*HYP";TAB 22;"HYP \.:% "
  90 PRINT AT 12,2;"F";TAB 7;"HYP=ADJ/COS";TAB 20;"COS->\.:% % "
 100 PRINT TAB 25;"ADJ"
 110 PRINT AT 15,2;"G";TAB 7;"TAN=OPP/ADJ";TAB 27;"\.:"
 120 PRINT AT 16,2;"H";TAB 7;"OPP=TAN*ADJ";TAB 26;"\.:%  OPP"
 130 PRINT AT 17,2;"I";TAB 7;"ADJ=OPP/TAN";TAB 20;"TAN->\.:% % "
 140 PRINT TAB 25;"ADJ";AT 19,2;"J";TAB 7;"%S%T%O%P"
 150 PRINT AT 21,0;"INPUT: REQUIRED FORMULAE(A TO J)"
 800 INPUT B$
 810 IF B$="A" THEN GOTO 1100
 820 IF B$="B" THEN GOTO 1300
 830 IF B$="C" THEN GOTO 1500
 840 IF B$="D" THEN GOTO 1700
 850 IF B$="E" THEN GOTO 1900
 860 IF B$="F" THEN GOTO 2100
 870 IF B$="G" THEN GOTO 2300
 880 IF B$="H" THEN GOTO 2500
 890 IF B$="I" THEN GOTO 2700
 900 IF B$="J" THEN STOP 
 910 IF B$<"A" OR B$>"J" THEN GOTO 800
\n1100 CLS 
\n1110 PRINT AT 2,2;"INPUT OPP"
\n1120 INPUT O
\n1130 PRINT AT 2,15;"OPP= ";O
\n1140 PRINT AT 4,2;"INPUT HYP"
\n1150 INPUT H
\n1160 PRINT AT 4,15;"HYP= ";H
\n1170 LET S=O/H
\n1180 LET X=ASN S*180/PI
\n1190 PRINT AT 6,5;"ANGLE= ";X;" DEGS"
\n1200 PRINT AT 10,3;"PRESS NEWLINE TO CONTINUE"
\n1210 INPUT A$
\n1220 GOTO 10
\n1300 CLS 
\n1310 PRINT AT 2,2;"INPUT SIN"
\n1320 INPUT S
\n1330 PRINT AT 2,15;"SIN= ";S;" DEGS"
\n1340 PRINT AT 4,2;"INPUT HYP"
\n1350 INPUT H
\n1360 PRINT AT 4,15;"HYP= ";H
\n1370 LET O=(SIN (S*PI/180))*H
\n1380 PRINT AT 6,5;"OPP= ";O
\n1390 PRINT AT 10,3;"PRESS NEWLINE TO CONTINUE"
\n1400 INPUT A$
\n1410 GOTO 10
\n1500 CLS 
\n1510 PRINT AT 2,2;"INPUT OPP"
\n1520 INPUT O
\n1530 PRINT AT 2,15;"OPP= ";O
\n1540 PRINT AT 4,2;"INPUT SIN"
\n1550 INPUT S
\n1560 PRINT AT 4,15;"SIN= ";S;" DEGS"
\n1570 LET H=O/(SIN (S*PI/180))
\n1580 PRINT AT 6,5;"HYP= ";H
\n1590 PRINT AT 10,3;"PRESS NEWLINE TO CONTINUE"
\n1600 INPUT A$
\n1610 GOTO 10
\n1700 CLS 
\n1710 PRINT AT 2,2;"INPUT ADJ"
\n1720 INPUT A
\n1730 PRINT AT 2,15;"ADJ= ";A
\n1740 PRINT AT 4,2;"INPUT HYP"
\n1750 INPUT H
\n1760 PRINT AT 4,15;"HYP= ";H
\n1770 LET C=A/H
\n1780 LET X=ACS C*180/PI
\n1790 PRINT AT 6,5;"ANGLE= ";X;" DEGS"
\n1800 PRINT AT 10,3;"PRESS NEWLINE TO CONTINUE"
\n1810 INPUT A$
\n1820 GOTO 10
\n1900 CLS 
\n1910 PRINT AT 2,2;"INPUT COS"
\n1920 INPUT C
\n1930 PRINT AT 2,15;"COS= ";C;" DEGS"
\n1940 PRINT AT 4,2;"INPUT HYP"
\n1950 INPUT H
\n1960 PRINT AT 4,15;"HYP= ";H
\n1970 LET A=(COS (C*PI/180))*H
\n1980 PRINT AT 6,5;"ADJ= ";A
\n1990 PRINT AT 10,3;"PRESS NEWLINE TO CONTINUE"
\n2000 INPUT A$
\n2010 GOTO 10
\n2100 CLS 
\n2110 PRINT AT 2,2;"INPUT ADJ"
\n2120 INPUT A
\n2130 PRINT AT 2,15;"ADJ= ";A
\n2140 PRINT AT 4,2;"INPUT COS"
\n2150 INPUT C
\n2160 PRINT AT 4,15;"COS= ";C;" DEGS"
\n2170 LET H=A/(COS (C*PI/180))
\n2180 PRINT AT 6,5;"HYP= ";H
\n2190 PRINT AT 10,3;"PRESS NEWLINE TO CONTINUE"
\n2200 INPUT A$
\n2210 GOTO 10
\n2300 CLS 
\n2310 PRINT AT 2,2;"INPUT OPP"
\n2320 INPUT O
\n2330 PRINT AT 2,15;"OPP= ";O
\n2340 PRINT AT 4,2;"INPUT ADJ"
\n2350 INPUT A
\n2360 PRINT AT 4,15;"ADJ= ";A
\n2370 LET T=O/A
\n2380 LET X=ATN T*180/PI
\n2390 PRINT AT 6,5;"ANGLE= ";X;" DEGS"
\n2400 PRINT AT 10,3;"PRESS NEWLINE TO CONTINUE"
\n2410 INPUT A$
\n2420 GOTO 10
\n2500 CLS 
\n2510 PRINT AT 2,2;"INPUT TAN"
\n2520 INPUT T
\n2530 PRINT AT 2,15;"TAN= ";T;" DEGS"
\n2540 PRINT AT 4,2;"INPUT ADJ"
\n2550 INPUT A
\n2560 PRINT AT 4,15;"ADJ= ";A
\n2570 LET O=(TAN (T*PI/180))*A
\n2580 PRINT AT 6,5;"OPP= ";O
\n2590 PRINT AT 10,3;"PRESS NEWLINE TO CONTINUE"
\n2600 INPUT A$
\n2610 GOTO 10
\n2700 CLS 
\n2710 PRINT AT 2,2;"INPUT OPP"
\n2720 INPUT O
\n2730 PRINT AT 2,15;"OPP= ";O
\n2740 PRINT AT 4,2;"INPUT TAN"
\n2750 INPUT T
\n2760 PRINT AT 4,15;"TAN= ";T;" DEGS"
\n2770 LET A=O/(TAN (T*PI/180))
\n2780 PRINT AT 6,5;"ADJ= ";A
\n2790 PRINT AT 10,3;"PRESS NEWLINE TO CONTINUE"
\n2800 INPUT A$
\n2810 GOTO 10
\n2820 CLEAR 
\n2830 SAVE "1025%7"
\n2840 RUN 

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

People

No people associated with this content.

Scroll to Top