56 lines
1.2 KiB
Plaintext
56 lines
1.2 KiB
Plaintext
/* t(x) = tangent of x */
|
|
define t(x) {
|
|
return s(x) / c(x)
|
|
}
|
|
|
|
/* y(y) = arcsine of y, domain [-1, 1], range [-pi/2, pi/2] */
|
|
define y(y) {
|
|
/* Handle angles with no tangent. */
|
|
if (y == -1) return -2 * a(1) /* -pi/2 */
|
|
if (y == 1) return 2 * a(1) /* pi/2 */
|
|
|
|
/* Tangent of angle is y / x, where x^2 + y^2 = 1. */
|
|
return a(y / sqrt(1 - y * y))
|
|
}
|
|
|
|
/* x(x) = arccosine of x, domain [-1, 1], range [0, pi] */
|
|
define x(x) {
|
|
auto a
|
|
|
|
/* Handle angle with no tangent. */
|
|
if (x == 0) return 2 * a(1) /* pi/2 */
|
|
|
|
/* Tangent of angle is y / x, where x^2 + y^2 = 1. */
|
|
a = a(sqrt(1 - x * x) / x)
|
|
if (a < 0) {
|
|
return a + 4 * a(1) /* add pi */
|
|
} else {
|
|
return a
|
|
}
|
|
}
|
|
|
|
|
|
scale = 50
|
|
p = 4 * a(1) /* pi */
|
|
d = p / 180 /* one degree in radians */
|
|
|
|
"Using radians:
|
|
"
|
|
" sin(-pi / 6) = "; s(-p / 6)
|
|
" cos(3 * pi / 4) = "; c(3 * p / 4)
|
|
" tan(pi / 3) = "; t(p / 3)
|
|
" asin(-1 / 2) = "; y(-1 / 2)
|
|
" acos(-sqrt(2) / 2) = "; x(-sqrt(2) / 2)
|
|
" atan(sqrt(3)) = "; a(sqrt(3))
|
|
|
|
"Using degrees:
|
|
"
|
|
" sin(-30) = "; s(-30 * d)
|
|
" cos(135) = "; c(135 * d)
|
|
" tan(60) = "; t(60 * d)
|
|
" asin(-1 / 2) = "; y(-1 / 2) / d
|
|
" acos(-sqrt(2) / 2) = "; x(-sqrt(2) / 2) / d
|
|
" atan(sqrt(3)) = "; a(sqrt(3)) / d
|
|
|
|
quit
|