# source:trunk/poppler/freetype-2.1.10/src/tools/cordic.py@2

Last change on this file since 2 was 2, checked in by Eugene Romanenko, 15 years ago

First import

File size: 1.6 KB
Line
1# compute arctangent table for CORDIC computations in fttrigon.c
2import sys, math
3
4#units  = 64*65536.0   # don't change !!
5units  = 256
6scale  = units/math.pi
7shrink = 1.0
8comma  = ""
9
10def calc_val( x ):
11    global units, shrink
12    angle  = math.atan(x)
13    shrink = shrink * math.cos(angle)
14    return angle/math.pi * units
15
16def  print_val( n, x ):
17    global comma
18
19    lo  = int(x)
20    hi  = lo + 1
21    alo = math.atan(lo)
22    ahi = math.atan(hi)
23    ax  = math.atan(2.0**n)
24
25    errlo = abs( alo - ax )
26    errhi = abs( ahi - ax )
27
28    if ( errlo < errhi ):
29      hi = lo
30
31    sys.stdout.write( comma + repr( int(hi) ) )
32    comma = ", "
33
34
35print ""
36print "table of arctan( 1/2^n ) for PI = " + repr(units/65536.0) + " units"
37
38# compute range of "i"
39r = [-1]
40r = r + range(32)
41
42for n in r:
43
44    if n >= 0:
45        x = 1.0/(2.0**n)    # tangent value
46    else:
47        x = 2.0**(-n)
48
49    angle  = math.atan(x)    # arctangent
50    angle2 = angle*scale     # arctangent in FT_Angle units
51
52    # determine which integer value for angle gives the best tangent
53    lo  = int(angle2)
54    hi  = lo + 1
55    tlo = math.tan(lo/scale)
56    thi = math.tan(hi/scale)
57
58    errlo = abs( tlo - x )
59    errhi = abs( thi - x )
60
61    angle2 = hi
62    if errlo < errhi:
63        angle2 = lo
64
65    if angle2 <= 0:
66        break
67
68    sys.stdout.write( comma + repr( int(angle2) ) )
69    comma = ", "
70
71    shrink = shrink * math.cos( angle2/scale)
72
73
74print
75print "shrink factor    = " + repr( shrink )
76print "shrink factor 2  = " + repr( shrink * (2.0**32) )
77print "expansion factor = " + repr(1/shrink)
78print ""
79
Note: See TracBrowser for help on using the repository browser.