David Turner | ebe85f5 | 2001-05-11 14:25:57 +0000 | [diff] [blame] | 1 | # compute arctangent table for CORDIC computations in fttrigon.c |
| 2 | import sys, math |
| 3 | |
David Turner | e664efa | 2004-06-04 17:41:59 +0000 | [diff] [blame] | 4 | #units = 64*65536.0 # don't change !! |
Alexei Podtelezhnikov | cbf3fb3 | 2012-12-21 14:20:25 -0500 | [diff] [blame] | 5 | units = 180 * 2**16 |
David Turner | ebe85f5 | 2001-05-11 14:25:57 +0000 | [diff] [blame] | 6 | scale = units/math.pi |
| 7 | shrink = 1.0 |
| 8 | comma = "" |
| 9 | |
David Turner | ebe85f5 | 2001-05-11 14:25:57 +0000 | [diff] [blame] | 10 | print "" |
| 11 | print "table of arctan( 1/2^n ) for PI = " + repr(units/65536.0) + " units" |
| 12 | |
Alexei Podtelezhnikov | b4ac30b | 2013-01-02 22:21:37 -0500 | [diff] [blame] | 13 | for n in range(1,32): |
David Turner | ebe85f5 | 2001-05-11 14:25:57 +0000 | [diff] [blame] | 14 | |
Alexei Podtelezhnikov | cbf3fb3 | 2012-12-21 14:20:25 -0500 | [diff] [blame] | 15 | x = 0.5**n # tangent value |
David Turner | ebe85f5 | 2001-05-11 14:25:57 +0000 | [diff] [blame] | 16 | |
Alexei Podtelezhnikov | cbf3fb3 | 2012-12-21 14:20:25 -0500 | [diff] [blame] | 17 | angle = math.atan(x) # arctangent |
| 18 | angle2 = round(angle*scale) # arctangent in FT_Angle units |
David Turner | ebe85f5 | 2001-05-11 14:25:57 +0000 | [diff] [blame] | 19 | |
| 20 | if angle2 <= 0: |
| 21 | break |
David Turner | e664efa | 2004-06-04 17:41:59 +0000 | [diff] [blame] | 22 | |
David Turner | ebe85f5 | 2001-05-11 14:25:57 +0000 | [diff] [blame] | 23 | sys.stdout.write( comma + repr( int(angle2) ) ) |
| 24 | comma = ", " |
David Turner | e664efa | 2004-06-04 17:41:59 +0000 | [diff] [blame] | 25 | |
Alexei Podtelezhnikov | cbf3fb3 | 2012-12-21 14:20:25 -0500 | [diff] [blame] | 26 | shrink /= math.sqrt( 1 + x*x ) |
David Turner | ebe85f5 | 2001-05-11 14:25:57 +0000 | [diff] [blame] | 27 | |
| 28 | print |
| 29 | print "shrink factor = " + repr( shrink ) |
Alexei Podtelezhnikov | cbf3fb3 | 2012-12-21 14:20:25 -0500 | [diff] [blame] | 30 | print "shrink factor 2 = " + repr( int( shrink * (2**32) ) ) |
| 31 | print "expansion factor = " + repr( 1/shrink ) |
David Turner | ebe85f5 | 2001-05-11 14:25:57 +0000 | [diff] [blame] | 32 | print "" |
Werner Lemberg | 9b774e2 | 2007-01-16 06:11:27 +0000 | [diff] [blame] | 33 | |