sourcelibs/Trig/demos/angles.xtl

1⍝!/usr/bin/env xetal 2⍝ Trig in use: the angles of a triangle from its sides, and the 3⍝ heading and distance of points seen from the origin. Run with 4⍝ "just demo Trig angles". 5"tr:" u̲se< "Trig" 6a ← 3.0 ⍝ the two short sides of a right triangle 7b ← 4.0 8c ← a ᵗʳh̲ypot b ⍝ the long side: 5 9c 10⍝ the law of cosines: the angle opposite each side 11ta ← ᵗʳa̲cos ((b × b) + (c × c) − a × a) ÷ 2.0 × b × c 12tb ← ᵗʳa̲cos ((a × a) + (c × c) − b × b) ÷ 2.0 × a × c 13tc ← ᵗʳa̲cos ((a × a) + (b × b) − c × c) ÷ 2.0 × a × b 14ᵗʳd̲egrees ta c̲at tb c̲at tc ⍝ 36.87 53.13 90 degrees 15(ta + tb + tc) − p̲i @ ⍝ they add to a half turn 16⍝ the corners of a square round the origin, then two points on the axes 17x ← 2.0 -2.0 -2.0 2.0 0.0 -3.0 18y ← 2.0 2.0 -2.0 -2.0 3.0 0.0 19ᵗʳd̲egrees y ᵗʳa̲tan2 x ⍝ headings: 45 135 -135 -45 90 180 20y ᵗʳh̲ypot x ⍝ distances: 2.83 four times, 3, 3