;All the trig functions presented here use radians as the unit of ; angle. ;One radian = 360/2*Pi degrees == 57.2957795 degrees. ; ;Constant values for the trig functions. ;This routine should be called before any of the trig functions are ; used - normally this would be done at startup. TO trig_init ;constants for the arctan function: t0 := 3.6404850 t1 := 2.9960992 t2 := 3.2474160E-1 t3 := - 1.0497842E-2 s0 := 3.6404853 s1 := 4.2095842 s2 := 1.0000000 _pio4 := 7.8539819E-1 _pio2 := 1.5707964 ;constants for the sin function: c0 := 1.5707963 c1 := - 6.4596373E-1 c2 := 7.9689682E-2 c3 := - 4.6737664E-3 c4 := 1.5148513E-4 _two_over_pi := 6.3661975E-1 END ;The arctangent function. ; TO arctan (arg) LOCAL b,ysq,x x := arg arg := ABS arg IF arg <= 1.0000000 [ IF arg = 1.0000000 [ IF x >= 0.0000000 RETURN _pio4 RETURN - _pio4 ] b := 0.0000000 ] ELSE [ b := _pio4 arg := (arg - 1.0000000) / (arg + 1.0000000) ] ysq := arg * arg arg := arg * ((((t3 * ysq + t2) * ysq + t1) * ysq + t0) / ((s2 * ysq + s1) * ysq + s0)) IF x >= 0.0000000 RETURN b + arg RETURN - (b + arg) END ;The arcsin function - needs the sqrt function and the arctan function. TO arcsin (arg) LOCAL temp,sign sign := arg >= 0.0000000 arg := ABS arg IF arg > 1.0000000 [ THROW 5 ] temp := sqrt (1.0000000 - arg * arg) IF arg > 0.7 temp := _pio2 - arctan (temp / arg) ELSE temp := arctan (arg / temp) IF sign RETURN temp RETURN - temp END ;The arccos function - needs the arcsin, sqrt, and the arctan functions. TO arccos (arg) RETURN _pio2 - arcsin (arg) END ;Returns the sin(arg) ;timing: first quadrant ~20mS. TO sin (y) LOCAL ysq,quad y := y * _two_over_pi quad := y AS INT IF quad > 3 [ y := y / 4.0000000 - (y / 4.0000000) AS INT y := 4.0000000 * y quad := y AS INT ] ELSE IF quad < 0 [ y := y / 4.0000000 - (y / 4.0000000) AS INT y := 4.0000000 * (y + 1) quad := y AS INT ] IF quad [ IF quad < 3 y := 2.0000000 - y ELSE y := y - 4.0000000 ] ysq := y * y y := ((((c4 * ysq + c3) * ysq + c2) * ysq + c1) * ysq + c0) * y RETURN y END ;faster first quadrant only version of sin - ~15mS TO sin (y) LOCAL ysq y := y *_two_over_pi ysq := y * y y := ((((c4 * ysq + c3) * ysq + c2) * ysq + c1) * ysq + c0) * y RETURN y END ;The cosine function TO cos(y) return sin(y+c0) END ;The tangent function To tan(y) return(sin(y) / cos(y)) END