-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathtrigonometry.scad
More file actions
552 lines (488 loc) · 34.3 KB
/
trigonometry.scad
File metadata and controls
552 lines (488 loc) · 34.3 KB
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
//////////////////////////////////////////////////////////////////////
// LibFile: trigonometry.scad
// Trigonometry shortcuts for people who can't be bothered to remember
// all the function relations, or silly acronyms like SOHCAHTOA.
// Includes:
// include <BOSL2/std.scad>
// FileGroup: Math
// FileSummary: Trigonometry shortcuts for when you can't recall the mnemonic SOHCAHTOA.
// FileFootnotes: STD=Included in std.scad
//////////////////////////////////////////////////////////////////////
_BOSL2_TRIGONOMETRY = is_undef(_BOSL2_STD) && (is_undef(BOSL2_NO_STD_WARNING) || !BOSL2_NO_STD_WARNING) ?
echo("Warning: triginometry.scad included without std.scad; dependencies may be missing\nSet BOSL2_NO_STD_WARNING = true to mute this warning.") true : true;
// Section: General Triangle Functions
// Function: law_of_cosines()
// Synopsis: Applies the Law of Cosines for an arbitrary triangle.
// Topics: Geometry, Trigonometry, Triangles
// See Also: law_of_sines()
// Usage:
// C = law_of_cosines(a, b, c);
// c = law_of_cosines(a, b, C=);
// Description:
// Applies the Law of Cosines for an arbitrary triangle. Given three side lengths, returns the
// reference angle in degrees for the corner opposite of the third side. Given two side lengths, and the
// reference angle between them, returns the length of the third side.
// Figure(2D;NoAxes;VPD=200;VPT=[0,25,20]):
// stroke([[-50,0], [10,60], [50,0]], closed=true, width=2);
// color("black") {
// translate([ 33,35]) text(text="a", size=8, halign="center", valign="center");
// translate([ 0,-6]) text(text="b", size=8, halign="center", valign="center");
// translate([-22,35]) text(text="c", size=8, halign="center", valign="center");
// }
// color("blue") {
// translate([-37, 6]) text(text="A", size=8, halign="center", valign="center");
// translate([ 9,51]) text(text="B", size=8, halign="center", valign="center");
// translate([ 38, 6]) text(text="C", size=8, halign="center", valign="center");
// }
// Arguments:
// a = The length of the first side.
// b = The length of the second side.
// c = The length of the third side.
// ---
// C = The reference angle in degrees of the corner opposite of the third side.
function law_of_cosines(a, b, c, C) =
// Triangle Law of Cosines:
// c^2 = a^2 + b^2 - 2*a*b*cos(C)
assert(num_defined([c,C]) == 1, "Must give exactly one of c= or C=.")
is_undef(c) ? sqrt(a*a + b*b - 2*a*b*cos(C)) :
acos(constrain((a*a + b*b - c*c) / (2*a*b), -1, 1));
// Function: law_of_sines()
// Synopsis: Applies the Law of Sines for an arbitrary triangle.
// Topics: Geometry, Trigonometry, Triangles
// See Also: law_of_cosines()
// Usage:
// B = law_of_sines(a, A, b);
// b = law_of_sines(a, A, B=);
// Description:
// Applies the Law of Sines for an arbitrary triangle. Given two triangle side lengths and the
// reference angle between them, returns the reference angle of the corner opposite of the second side. Given a side
// length, the opposing reference angle, and a second reference angle, returns the length of the side opposite of the
// second reference angle.
// Figure(2D;NoAxes;VPD=200;VPT=[0,25,0]):
// stroke([[-50,0], [10,60], [50,0]], closed=true, width=2);
// color("black") {
// translate([ 33,35]) text(text="a", size=8, halign="center", valign="center");
// translate([ 0,-6]) text(text="b", size=8, halign="center", valign="center");
// translate([-22,35]) text(text="c", size=8, halign="center", valign="center");
// }
// color("blue") {
// translate([-37, 6]) text(text="A", size=8, halign="center", valign="center");
// translate([ 9,51]) text(text="B", size=8, halign="center", valign="center");
// translate([ 38, 6]) text(text="C", size=8, halign="center", valign="center");
// }
// Arguments:
// a = The length of the first side.
// A = The reference angle in degrees of the corner opposite of the first side.
// b = The length of the second side.
// ---
// B = The reference angle in degrees of the corner opposite of the second side.
function law_of_sines(a, A, b, B) =
// Triangle Law of Sines:
// a/sin(A) = b/sin(B) = c/sin(C)
assert(num_defined([b,B]) == 1, "Must give exactly one of b= or B=.")
let( r = a/sin(A) )
is_undef(b) ? r*sin(B) :
asin(constrain(b/r, -1, 1));
// Section: Right Triangle Functions
// This is a set of functions to make it easier to perform trig calculations on right triangles.
// In general, all these functions are named using these abbreviations:
// - **ang**: The reference reference angle size in degrees.
// - **hyp**: The length of the Hypotenuse.
// - **adj**: The length of the side adjacent to the reference reference angle.
// - **opp**: The length of the side opposite to the reference reference angle.
// .
// If you know two of those, and want to know the value of a third, you will need to call a
// function named like `AAA_BBB_to_CCC()`. For example, if you know the length of the hypotenuse,
// and the length of the side adjacent to the reference reference angle, and want to learn the length of the side
// opposite to the reference reference angle, you will call `opp = hyp_adj_to_opp(hyp,adj);`.
// Figure(2D;NoAxes;VPD=250:VPT=[10,25,0]):
// color("brown") {
// stroke([[40,0], [40,10], [50,10]]);
// left(50) stroke(arc(r=37,angle=30));
// }
// color("lightgreen") stroke([[-50,0], [50,60], [50,0]], closed=true, width=2);
// color("black") {
// translate([ 62,25]) text(text="opp", size=8, halign="center", valign="center");
// translate([ 0,-7]) text(text="adj", size=8, halign="center", valign="center");
// translate([ 0,40]) text(text="hyp", size=8, halign="center", valign="center");
// translate([-25, 5]) text(text="ang", size=7, halign="center", valign="center");
// }
// Function: hyp_opp_to_adj()
// Synopsis: Returns the adjacent side length from the lengths of the hypotenuse and the opposite side.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// adj = hyp_opp_to_adj(hyp,opp);
// Description:
// Given the lengths of the hypotenuse and opposite side of a right triangle, returns the length
// of the adjacent side.
// Arguments:
// hyp = The length of the hypotenuse of the right triangle.
// opp = The length of the side of the right triangle that is opposite from the reference reference angle.
// Example:
// adj = hyp_opp_to_adj(5,3); // Returns: 4
function hyp_opp_to_adj(hyp,opp) =
assert(is_finite(hyp+opp) && hyp>=0 && opp>=0,
"Triangle side lengths should be a positive numbers." )
sqrt(hyp*hyp-opp*opp);
// Function: opp_hyp_to_adj()
// Synopsis: Returns the adjacent side length from the lengths of the opposite side and the hypotenuse.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// adj = opp_hyp_to_adj(opp,hyp);
// Description:
// Given the lengths of the opposite side and hypotenuse of a right triangle, returns the length
// of the adjacent side.
// Arguments:
// opp = The length of the side of the right triangle that is opposite from the reference reference angle.
// hyp = The length of the hypotenuse of the right triangle.
// Example:
// adj = opp_hyp_to_adj(3,5); // Returns: 4
function opp_hyp_to_adj(opp,hyp) = hyp_opp_to_adj(hyp,opp);
// Function: hyp_ang_to_adj()
// Synopsis: Returns the adjacent side length from the length of the hypotenuse and the reference reference angle.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// adj = hyp_ang_to_adj(hyp,ang);
// Description:
// Given the length of the hypotenuse and the reference reference angle of a right triangle,
// returns the length of the adjacent side.
// Arguments:
// hyp = The length of the hypotenuse of the right triangle.
// ang = The reference reference angle of the right triangle in degrees
// Example:
// adj = hyp_ang_to_adj(8,60); // Returns: 4
function hyp_ang_to_adj(hyp,ang) =
assert(is_finite(hyp) && hyp>=0, "Triangle side length should be a positive number." )
assert(is_finite(ang) && ang>-90 && ang<90, "The reference angle should be an acute reference angle." )
hyp*cos(ang);
// Function: ang_hyp_to_adj()
// Synopsis: Returns the adjacent side length from the reference reference angle and the length of the hypotenuse.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// adj = ang_hyp_to_adj(ang,hyp);
// Description:
// Given the reference reference angle and the length of the hypotenuse of a right triangle,
// returns the length of the adjacent side.
// Arguments:
// ang = The reference reference angle of the right triangle in degrees
// hyp = The length of the hypotenuse of the right triangle.
// Example:
// adj = ang_hyp_to_adj(60,8); // Returns: 4
function ang_hyp_to_adj(ang,hyp) = hyp_ang_to_adj(hyp, ang);
// Function: opp_ang_to_adj()
// Synopsis: Returns the adjacent side length from the length of the opposite side and the reference reference angle.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// adj = opp_ang_to_adj(opp,ang);
// Description:
// Given the length of the opposite side and the reference reference angle of a right triangle,
// returns the length of the adjacent side.
// Arguments:
// opp = The length of the side of the right triangle that is opposite from the reference reference angle.
// ang = The reference reference angle of the right triangle in degrees
// Example:
// adj = opp_ang_to_adj(8,45); // Returns: 8
function opp_ang_to_adj(opp,ang) =
assert(is_finite(opp) && opp>=0, "Triangle side length should be a positive number." )
assert(is_finite(ang) && ang>-90 && ang<90, "The reference angle should be an acute reference angle." )
opp/tan(ang);
// Function: ang_opp_to_adj()
// Synopsis: Returns the adjacent side length from the reference reference angle and the length of the opposite side.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// adj = ang_opp_to_adj(ang,opp);
// Description:
// Given the reference reference angle of a right triangle, and the length of the side opposite of it,
// returns the length of the adjacent side.
// Arguments:
// ang = The reference reference angle of the right triangle in degrees
// opp = The length of the side of the right triangle that is opposite from the reference reference angle.
// Example:
// adj = ang_opp_to_adj(45,8); // Returns: 8
function ang_opp_to_adj(ang,opp) = opp_ang_to_adj(opp,ang);
// Function: hyp_adj_to_opp()
// Synopsis: Returns the opposite side length from the lengths of the hypotenuse and the adjacent side.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// opp = hyp_adj_to_opp(hyp,adj);
// Description:
// Given the lengths of the hypotenuse and the adjacent side, returns the length of the opposite side.
// Arguments:
// hyp = The length of the hypotenuse of the right triangle.
// adj = The length of the side of the right triangle that is adjacent to the reference reference angle.
// Example:
// opp = hyp_adj_to_opp(5,4); // Returns: 3
function hyp_adj_to_opp(hyp,adj) =
assert(is_finite(hyp) && hyp>=0 && is_finite(adj) && adj>=0,
"Triangle side lengths should be a positive numbers." )
sqrt(hyp*hyp-adj*adj);
// Function: adj_hyp_to_opp()
// Synopsis: Returns the opposite side length from the lengths of the adjacent side and the hypotenuse.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// opp = adj_hyp_to_opp(adj,hyp);
// Description:
// Given the lengths of the adjacent side and the hypotenuse, returns the length of the opposite side.
// Arguments:
// adj = The length of the side of the right triangle that is adjacent to the reference reference angle.
// hyp = The length of the hypotenuse of the right triangle.
// Example:
// opp = adj_hyp_to_opp(4,5); // Returns: 3
function adj_hyp_to_opp(adj,hyp) = hyp_adj_to_opp(hyp,adj);
// Function: hyp_ang_to_opp()
// Synopsis: Returns the opposite side length from the length of the hypotenuse and the reference reference angle.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// opp = hyp_ang_to_opp(hyp,ang);
// Description:
// Given the length of the hypotenuse of a right triangle and the reference reference angle, returns the length of the opposite side.
// Arguments:
// hyp = The length of the hypotenuse of the right triangle.
// ang = The reference reference angle of the right triangle in degrees
// Example:
// opp = hyp_ang_to_opp(8,30); // Returns: 4
function hyp_ang_to_opp(hyp,ang) =
assert(is_finite(hyp)&&hyp>=0, "Triangle side length should be a positive number." )
assert(is_finite(ang) && ang>-90 && ang<90, "The reference angle should be an acute reference angle." )
hyp*sin(ang);
// Function: ang_hyp_to_opp()
// Synopsis: Returns the opposite side length from the reference reference angle and the length of the hypotenuse.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// opp = ang_hyp_to_opp(ang,hyp);
// Description:
// Given the the reference reference angle and the length of the hypotenuse of a right triangle, returns the length of the opposite side.
// Arguments:
// ang = The reference reference angle of the right triangle in degrees
// hyp = The length of the hypotenuse of the right triangle.
// Example:
// opp = ang_hyp_to_opp(30,8); // Returns: 4
function ang_hyp_to_opp(ang,hyp) = hyp_ang_to_opp(hyp,ang);
// Function: adj_ang_to_opp()
// Synopsis: Returns the opposite side length from the length of the adjacent side and the reference reference angle.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// opp = adj_ang_to_opp(adj,ang);
// Description:
// Given the length of the adjacent side of a right triangle, and the reference reference angle, returns the length of the opposite side.
// Arguments:
// adj = The length of the side of the right triangle that is adjacent to the reference reference angle.
// ang = The reference reference angle of the right triangle in degrees
// Example:
// opp = adj_ang_to_opp(8,45); // Returns: 8
function adj_ang_to_opp(adj,ang) =
assert(is_finite(adj)&&adj>=0, "Triangle side length should be a positive number." )
assert(is_finite(ang) && ang>-90 && ang<90, "The reference angle should be an acute reference angle." )
adj*tan(ang);
// Function: ang_adj_to_opp()
// Synopsis: Returns the opposite side length from the reference reference angle and the length of the adjacent side.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// opp = ang_adj_to_opp(ang,adj);
// Description:
// Given the reference reference angle and the length of the adjacent side of a right triangle, returns the length of the opposite side.
// Arguments:
// ang = The reference reference angle of the right triangle in degrees
// adj = The length of the side of the right triangle that is adjacent to the reference reference angle.
// Example:
// opp = ang_adj_to_opp(45,8); // Returns: 8
function ang_adj_to_opp(ang,adj) = adj_ang_to_opp(adj,ang);
// Function: adj_opp_to_hyp()
// Synopsis: Returns the hypotenuse length from the lengths of the adjacent and opposite sides.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// hyp = adj_opp_to_hyp(adj,opp);
// Description:
// Given the length of the adjacent and opposite sides of a right triangle, returns the length of the hypotenuse.
// Arguments:
// adj = The length of the side of the right triangle that is adjacent to the reference reference angle.
// opp = The length of the side of the right triangle that is opposite from the reference reference angle.
// Example:
// hyp = adj_opp_to_hyp(3,4); // Returns: 5
function adj_opp_to_hyp(adj,opp) =
assert(is_finite(opp) && opp>=0 && is_finite(adj) && adj>=0,
"Triangle side lengths should be a positive numbers." )
norm([opp,adj]);
// Function: opp_adj_to_hyp()
// Synopsis: Returns the hypotenuse length from the lengths of the opposite and adjacent sides.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// hyp = opp_adj_to_hyp(opp,adj);
// Description:
// Given the length of the opposite and adjacent sides of a right triangle, returns the length of the hypotenuse.
// Arguments:
// opp = The length of the side of the right triangle that is opposite from the reference reference angle.
// adj = The length of the side of the right triangle that is adjacent to the reference reference angle.
// Example:
// hyp = opp_adj_to_hyp(4,3); // Returns: 5
function opp_adj_to_hyp(opp,adj) = adj_opp_to_hyp(adj,opp);
// Function: adj_ang_to_hyp()
// Synopsis: Returns the hypotenuse length from the length of the adjacent side and the reference reference angle.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// hyp = adj_ang_to_hyp(adj,ang);
// Description:
// For a right triangle, given the length of the adjacent side, and the reference reference angle, returns the length of the hypotenuse.
// Arguments:
// adj = The length of the side of the right triangle that is adjacent to the reference reference angle.
// ang = The reference reference angle of the right triangle in degrees
// Example:
// hyp = adj_ang_to_hyp(4,60); // Returns: 8
function adj_ang_to_hyp(adj,ang) =
assert(is_finite(adj) && adj>=0, "Triangle side length should be a positive number." )
assert(is_finite(ang) && ang>-90 && ang<90, "The reference angle should be an acute reference angle." )
adj/cos(ang);
// Function: ang_adj_to_hyp()
// Synopsis: Returns the hypotenuse length from the reference reference angle and length of the adjacent side.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// hyp = ang_adj_to_hyp(ang,adj);
// Description:
// For a right triangle, given the reference reference angle and length of the adjacent side, returns the length of the hypotenuse.
// Arguments:
// ang = The reference reference angle of the right triangle in degrees
// adj = The length of the side of the right triangle that is adjacent to the reference reference angle.
// Example:
// hyp = ang_adj_to_hyp(60,4); // Returns: 8
function ang_adj_to_hyp(ang,adj) = adj_ang_to_hyp(adj,ang);
// Function: opp_ang_to_hyp()
// Synopsis: Returns the hypotenuse length from the length of the opposite side and the reference reference angle.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// hyp = opp_ang_to_hyp(opp,ang);
// Description:
// For a right triangle, given the length of the opposite side, and the reference reference angle, returns the length of the hypotenuse.
// Arguments:
// opp = The length of the side of the right triangle that is opposite from the reference reference angle.
// ang = The reference reference angle of the right triangle in degrees
// Example:
// hyp = opp_ang_to_hyp(4,30); // Returns: 8
function opp_ang_to_hyp(opp,ang) =
assert(is_finite(opp) && opp>=0, "Triangle side length should be a positive number." )
assert(is_finite(ang) && ang>-90 && ang<90, "The reference angle should be an acute reference angle." )
opp/sin(ang);
// Function: ang_opp_to_hyp()
// Synopsis: Returns the hypotenuse length from the reference reference angle and the length of the opposite side.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// hyp = ang_opp_to_hyp(ang,opp);
// Description:
// For a right triangle, given the reference reference angle and the length of the opposite side, returns the length of the hypotenuse.
// Arguments:
// ang = The reference reference angle of the right triangle in degrees
// opp = The length of the side of the right triangle that is opposite from the reference reference angle.
// Example:
// hyp = opp_ang_to_hyp(30,4); // Returns: 8
function ang_opp_to_hyp(ang,opp) = opp_ang_to_hyp(opp,ang);
// Function: hyp_adj_to_ang()
// Synopsis: Returns the reference reference angle from the lengths of the hypotenuse and the adjacent side.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// ang = hyp_adj_to_ang(hyp,adj);
// Description:
// For a right triangle, given the lengths of the hypotenuse and the adjacent side, returns the reference reference angle.
// Arguments:
// hyp = The length of the hypotenuse of the right triangle.
// adj = The length of the side of the right triangle that is adjacent to the reference reference angle.
// Example:
// ang = hyp_adj_to_ang(8,4); // Returns: 60 degrees
function hyp_adj_to_ang(hyp,adj) =
assert(is_finite(hyp) && hyp>0 && is_finite(adj) && adj>=0,
"Triangle side lengths should be positive numbers." )
acos(adj/hyp);
// Function: adj_hyp_to_ang()
// Synopsis: Returns the reference angle from the lengths of the adjacent side and the hypotenuse.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// ang = adj_hyp_to_ang(adj,hyp);
// Description:
// For a right triangle, given the lengths of the adjacent side and the hypotenuse, returns the reference reference angle.
// Arguments:
// adj = The length of the side of the right triangle that is adjacent to the reference reference angle.
// hyp = The length of the hypotenuse of the right triangle.
// Example:
// ang = adj_hyp_to_ang(4,8); // Returns: 60 degrees
function adj_hyp_to_ang(adj,hyp) = hyp_adj_to_ang(hyp,adj);
// Function: hyp_opp_to_ang()
// Synopsis: Returns the reference reference angle from the lengths of the hypotenuse and the opposite side.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// ang = hyp_opp_to_ang(hyp,opp);
// Description:
// For a right triangle, given the lengths of the hypotenuse and the opposite sides, returns the reference reference angle.
// Arguments:
// hyp = The length of the hypotenuse of the right triangle.
// opp = The length of the side of the right triangle that is opposite from the reference reference angle.
// Example:
// ang = hyp_opp_to_ang(8,4); // Returns: 30 degrees
function hyp_opp_to_ang(hyp,opp) =
assert(is_finite(hyp+opp) && hyp>0 && opp>=0,
"Triangle side lengths should be positive numbers." )
asin(opp/hyp);
// Function: opp_hyp_to_ang()
// Synopsis: Returns the reference reference angle from the lengths of the opposite side and the hypotenuse.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// ang = opp_hyp_to_ang(opp,hyp);
// Description:
// For a right triangle, given the lengths of the opposite side and the hypotenuse, returns the reference reference angle.
// Arguments:
// opp = The length of the side of the right triangle that is opposite from the reference reference angle.
// hyp = The length of the hypotenuse of the right triangle.
// Example:
// ang = opp_hyp_to_ang(4,8); // Returns: 30 degrees
function opp_hyp_to_ang(opp,hyp) = hyp_opp_to_ang(hyp,opp);
// Function: adj_opp_to_ang()
// Synopsis: Returns the reference angle from the lengths of the adjacent and opposite sides.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// ang = adj_opp_to_ang(adj,opp);
// Description:
// For a right triangle, given the lengths of the adjacent and opposite sides, returns the reference angle of the corner.
// Arguments:
// adj = The length of the side of the right triangle that is adjacent to the reference reference angle.
// opp = The length of the side of the right triangle that is opposite from the reference reference angle.
// Example:
// ang = adj_opp_to_ang(sqrt(3)/2,0.5); // Returns: 30 degrees
function adj_opp_to_ang(adj,opp) =
assert(is_finite(adj+opp) && adj>0 && opp>=0,
"Triangle side lengths should be positive numbers." )
atan2(opp,adj);
// Function: opp_adj_to_ang()
// Synopsis: Returns the reference reference angle from the lengths of the opposite and adjacent sides.
// Topics: Geometry, Trigonometry, Triangles
// See Also: adj_ang_to_hyp(), adj_ang_to_opp(), adj_opp_to_ang(), adj_opp_to_hyp(), hyp_adj_to_ang(), hyp_adj_to_opp(), hyp_ang_to_adj(), hyp_ang_to_opp(), hyp_opp_to_adj(), hyp_opp_to_ang(), opp_ang_to_adj(), opp_ang_to_hyp(), ang_adj_to_hyp(), ang_adj_to_opp(), opp_adj_to_ang(), opp_adj_to_hyp(), adj_hyp_to_ang(), adj_hyp_to_opp(), ang_hyp_to_adj(), ang_hyp_to_opp(), opp_hyp_to_adj(), opp_hyp_to_ang(), ang_opp_to_adj(), ang_opp_to_hyp()
// Usage:
// ang = opp_adj_to_ang(opp,adj);
// Description:
// For a right triangle, given the lengths of the opposite and adjacent sides, returns the reference reference angle.
// Arguments:
// opp = The length of the side of the right triangle that is opposite from the reference reference angle.
// adj = The length of the side of the right triangle that is adjacent to the reference reference angle.
// Example:
// ang = opp_adj_to_ang(0.5,sqrt(3)/2); // Returns: 30 degrees
function opp_adj_to_ang(opp,adj) = adj_opp_to_ang(adj,opp);
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap