-
Notifications
You must be signed in to change notification settings - Fork 0
/
TRIG-commented.txt
307 lines (277 loc) · 8.72 KB
/
TRIG-commented.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
-- The variables correspond to labelled dimensions as: --
-- Side A: [2] --
-- Side B: [6] --
-- Side C: [4] --
-- Angle D: [5] --
-- Angle E: [1] --
-- Angle F: [3] --
-- Setup --
0→A:0→B:0→C:0→D:0→E:0→F:0→N:1→M
If sin(π:0→M -- save angle units to revert to after execution --
Degree -- defaults to degrees during execution --
AxesOff
GridOff
BackgroundOff
RectGC
FnOff
BorderColor 4
0→Xmin
1→Xmax
0→Ymin
41/66→Ymax -- 1:1 display ratio --
-- Get Dimensions --
Lbl 0
If N≠3:Then -- N is number of specified dimensions, 3 fully defines a triangle --
Lbl A -- redraw for ambiguous case handling --
ClrHome
ClrDraw -- redraw whole interface every time a dimension is modified --
Line(.2,.055,.8,.055,1,11 -- interface triangle --
Line(.8,.055,.5,.555,1,11
Line(.5,.555,.2,.055,1,11
If E:Then
TextColor(10 -- label dimensions; blue if specified, gray [key] if not --
Text(142,30,E
Else
TextColor(23
Text(142,30,"[1]
End
If A:Then
TextColor(10
Text(150,124,A
Else
TextColor(23
Text(150,124,"[2]
End
If F:Then
TextColor(10
Text(142,218,F
Else
TextColor(23
Text(142,218,"[3]
End
If C:Then
TextColor(10
Text(76,66,C
Else
TextColor(23
Text(76,66,"[4]
End
If D:Then
TextColor(10
Text(2,124,D
Else
TextColor(23
Text(2,124,"[5]
End
If B:Then
TextColor(10
Text(76,182,B
Else
TextColor(23
Text(76,182,"[6]
End
If N=3:Goto B -- return to ambiguous case handling --
While 1 -- loop until valid keypress --
getKey→K
-- the keys were chosen such that their position on the keypad corresponds to their position on the screen --
If K=92:Then -- '1' key --
If not(E:N+1→N
Input "Angle?",E
If not(E:N-1→N
Goto 0
End
If K=93:Then -- '2' key --
If not(A:N+1→N
Input "Length?",A
If not(A:N-1→N
Goto 0
End
If K=94:Then -- '3' key --
If not(F:N+1→N
Input "Angle?",F
If not(F:N-1→N
Goto 0
End
If K=82:Then -- '4' key --
If not(C:N+1→N
Input "Length?",C
If not(C:N-1→N
Goto 0
End
If K=83:Then -- '5' key --
If not(D:N+1→N
Input "Angle?",D
If not(D:N-1→N
Goto 0
End
If K=84:Then -- '6' key --
If not(B:N+1→N
Input "Length?",B
If not(B:N-1→N
Goto 0
End
If K=95:Then -- '+' key; help menu --
ClrHome
Disp " [+] for help",""," CLEAR to quit + erase",""," MODE to toggle deg/rad","","",""," Ver. 2.1
Pause
ClrHome
DispGraph
End
If K=45:Then -- 'clear' key; quit pgrm --
" -- empty error message --
Goto QT
End
If K=22:Then -- 'mode' key; toggle deg/rad --
If sin(π:Then
Radian
Else
Degree
End
End
End
End -- end of initial interface --
-- statements below like "If ABC" are product truthy tests to check which dimensions are defined --
-- check if dimensions form a valid triangle --
If A<0 or B<0 or C<0 or D<0 or E<0 or F<0 or D+E≥180° or D+F≥180° or E+F≥180° or DEF or ABC and (A-B-C≥0 or B-A-C≥0 or C-B-A≥0):Goto ER
-- Ambiguous Case --
If EAB or FAC or DBA or FBC or DCA or ECB:Then -- check if dimensions result in the ambiguous case (ASS)--
0→θ
If D:A→O -- determine opposite side --
If E:B→O
If F:C→O
If D+E+F≥90°:Then
If O≤(A+B+C-O):Then
Goto ER -- if triangle is obtuse, the opposite side must be the hypotenuse for it to be valid --
Else
Goto NO -- obtuse ASS triangles are not ambiguous, skip ahead --
End
End
If O<(A+B+C-O)sin(D+E+F):Goto ER -- opposite too short --
If O≥(A+B+C-O):Goto NO -- opposite long enough such that there is no "obtuse solution", skip ahead --
Goto A -- go draw triangle again with the three defined dimensions --
Lbl B
TextColor(12
Text(116,83,"Is Highlighted? -- prompt user to select which ambiguous case they want --
Text(130,66,"< acute or obtuse >
TextColor(13
If EAB or FAC:Text(2,124,"[5] -- make pertinent angle pink --
If DBA or FBC:Text(142,30,"[1]
If DCA or ECB:Text(142,218,"[3]
2→θ
While θ=2
getKey→K
If K=24:0→θ -- left arrow; acute --
If K=26:1→θ -- right arrow; obtuse --
End
Lbl NO
If EAB:Then
abs(sin⁻¹(Asin(E)/B)-θ180°→D -- sine law for angle, where "θ180°" term finds the alternate solution if "obtuse" was selected previously --
Goto DN
End
If FAC:Then
abs(sin⁻¹(Asin(F)/C)-θ180°→D
Goto DN
End
If DBA:Then
abs(sin⁻¹(Bsin(D)/A)-θ180°→E
Goto DN
End
If FBC:Then
abs(sin⁻¹(Bsin(F)/C)-θ180°→E
Goto DN
End
If DCA:Then
abs(sin⁻¹(Csin(D)/A)-θ180°→F
Goto DN
End
If ECB:Then
abs(sin⁻¹(Csin(E)/B)-θ180°→F
Goto DN
End
End
-- Solve Unknown Dimensions --
Lbl DN
While not(ABCDEF
If EF and not(D:180°-E-F→D -- angle sum property --
If DF and not(E:180°-D-F→E
If DE and not(F:180°-D-E→F
If BCD and not(A:√(B²+C²-2BCcos(D→A -- cosine law for side --
If ACE and not(B:√(A²+C²-2ACcos(E→B
If ABF and not(C:√(A²+B²-2ABcos(F→C
If ABC and not(D:cos⁻¹((A²-B²-C²)/(-2BC→D -- cosine law for angle --
If ABC and not(E:cos⁻¹((B²-A²-C²)/(-2AC→E
If ABC and not(F:cos⁻¹((C²-A²-B²)/(-2AB→F
If ADE and not(B:Asin(E)/sin(D→B -- sine law for side --
If ADF and not(C:Asin(F)/sin(D→C
If BED and not(A:Bsin(D)/sin(E→A
If BEF and not(C:Bsin(F)/sin(E→C
If CFD and not(A:Csin(D)/sin(F→A
If CFE and not(B:Csin(E)/sin(F→B
End
-- Render Scale Triangle --
ClrDraw
Ccos(E→P -- vertex D at (P,Q) --
Csin(E→Q
0→L
If P<L:-P→L -- leftmost vertex of triangle --
A→R
If P≥R:P→R -- rightmost vertex of triangle --
If L+R≥66Q/41:L+R→S -- determine scale factor; horizontal --
If L+R<66Q/41:66Q/41→S -- vertical --
(P+L)/S→P -- apply scale so everything fits in Xmin/max and Ymin/max --
Q/S→Q
L/S→V -- vertex E at (V,0) --
(A+L)/S→W -- vertex F at (W,0) --
-- piecewise equations to ensure dimensions are plotted within display area --
-- the functions look like _/‾ --
"0(X≤0) + X(0<X and X<236) + 236(236≤X)"→Y₉
"148(Z≤0) + (148-Z)(0<Z and Z<148) + 0(148≤Z)"→Y₀
FnOff
Line(V,0.002,W,0.002,1,11 -- render triangle --
Line(W,0,P,Q,1,11
Line(P,Q,V,0.002,1,11
TextColor(10 -- angles in blue --
round(264P-6,0→X -- row to plot the dimension --
round(264Q-20,0→Z -- column to plot the dimension --
Text(Y₀,Y₉,round(D,1 -- X and Z are passed through the piecewise functions --
round(264V+8,0→X
Text(148,Y₉,round(E,1
round(264W-28,0→X
Text(148,Y₉,round(F,1
TextColor(12 -- side lengths in black --
round(132(V+W),0→X
Text(148,Y₉,round(A,2
round(132(P+W),0→X
round(132Q-14,0→Z
Text(Y₀,Y₉,round(B,2
round(132(V+P),0→X
round(132Q,0→Z
Text(Y₀,Y₉,round(C,2
Pause -- show triangle until user hits 'enter' --
Goto QT -- skips error --
Lbl ER
"invalid dimensions! -- stores error message to 'Ans' --
-- Reset Graph --
Lbl QT
ClrDraw
ZFrac1/4
BorderColor 1
FnOn 1,2,3,4,5,6,7,8
AxesOn
ClrHome
DelVar Y₉
DelVar Y₀
If ABCDEF:Then
Disp A,B,C,"",D,E,F -- print all dimensions with more digits --
Output(1,2,"Base:
Output(2,2,"Right:
Output(3,2,"Left:
Output(5,2,"∠Apex:
Output(6,2,"∠Left:
Output(7,2,"∠Right:
ACsin(E)/2→X -- area of the triangle --
Else
Disp Ans -- error message --
End
Degree
If M:Radian