* src/tools/cordic.py: Bring up to date with trigonometric core.
This commit is contained in:
parent
3ffb822e92
commit
cbf3fb39fd
|
@ -1,3 +1,7 @@
|
||||||
|
2012-12-21 Alexei Podtelezhnikov <apodtele@gmail.com>
|
||||||
|
|
||||||
|
* src/tools/cordic.py: Bring up to date with trigonometric core.
|
||||||
|
|
||||||
2012-12-21 Werner Lemberg <wl@gnu.org>
|
2012-12-21 Werner Lemberg <wl@gnu.org>
|
||||||
|
|
||||||
Check parameters of `FT_Outline_New'.
|
Check parameters of `FT_Outline_New'.
|
||||||
|
|
|
@ -2,65 +2,20 @@
|
||||||
import sys, math
|
import sys, math
|
||||||
|
|
||||||
#units = 64*65536.0 # don't change !!
|
#units = 64*65536.0 # don't change !!
|
||||||
units = 256
|
units = 180 * 2**16
|
||||||
scale = units/math.pi
|
scale = units/math.pi
|
||||||
shrink = 1.0
|
shrink = 1.0
|
||||||
comma = ""
|
comma = ""
|
||||||
|
|
||||||
def calc_val( x ):
|
|
||||||
global units, shrink
|
|
||||||
angle = math.atan(x)
|
|
||||||
shrink = shrink * math.cos(angle)
|
|
||||||
return angle/math.pi * units
|
|
||||||
|
|
||||||
def print_val( n, x ):
|
|
||||||
global comma
|
|
||||||
|
|
||||||
lo = int(x)
|
|
||||||
hi = lo + 1
|
|
||||||
alo = math.atan(lo)
|
|
||||||
ahi = math.atan(hi)
|
|
||||||
ax = math.atan(2.0**n)
|
|
||||||
|
|
||||||
errlo = abs( alo - ax )
|
|
||||||
errhi = abs( ahi - ax )
|
|
||||||
|
|
||||||
if ( errlo < errhi ):
|
|
||||||
hi = lo
|
|
||||||
|
|
||||||
sys.stdout.write( comma + repr( int(hi) ) )
|
|
||||||
comma = ", "
|
|
||||||
|
|
||||||
|
|
||||||
print ""
|
print ""
|
||||||
print "table of arctan( 1/2^n ) for PI = " + repr(units/65536.0) + " units"
|
print "table of arctan( 1/2^n ) for PI = " + repr(units/65536.0) + " units"
|
||||||
|
|
||||||
# compute range of "i"
|
for n in range(0,32):
|
||||||
r = [-1]
|
|
||||||
r = r + range(32)
|
|
||||||
|
|
||||||
for n in r:
|
x = 0.5**n # tangent value
|
||||||
|
|
||||||
if n >= 0:
|
angle = math.atan(x) # arctangent
|
||||||
x = 1.0/(2.0**n) # tangent value
|
angle2 = round(angle*scale) # arctangent in FT_Angle units
|
||||||
else:
|
|
||||||
x = 2.0**(-n)
|
|
||||||
|
|
||||||
angle = math.atan(x) # arctangent
|
|
||||||
angle2 = angle*scale # arctangent in FT_Angle units
|
|
||||||
|
|
||||||
# determine which integer value for angle gives the best tangent
|
|
||||||
lo = int(angle2)
|
|
||||||
hi = lo + 1
|
|
||||||
tlo = math.tan(lo/scale)
|
|
||||||
thi = math.tan(hi/scale)
|
|
||||||
|
|
||||||
errlo = abs( tlo - x )
|
|
||||||
errhi = abs( thi - x )
|
|
||||||
|
|
||||||
angle2 = hi
|
|
||||||
if errlo < errhi:
|
|
||||||
angle2 = lo
|
|
||||||
|
|
||||||
if angle2 <= 0:
|
if angle2 <= 0:
|
||||||
break
|
break
|
||||||
|
@ -68,12 +23,11 @@ for n in r:
|
||||||
sys.stdout.write( comma + repr( int(angle2) ) )
|
sys.stdout.write( comma + repr( int(angle2) ) )
|
||||||
comma = ", "
|
comma = ", "
|
||||||
|
|
||||||
shrink = shrink * math.cos( angle2/scale)
|
shrink /= math.sqrt( 1 + x*x )
|
||||||
|
|
||||||
|
|
||||||
print
|
print
|
||||||
print "shrink factor = " + repr( shrink )
|
print "shrink factor = " + repr( shrink )
|
||||||
print "shrink factor 2 = " + repr( shrink * (2.0**32) )
|
print "shrink factor 2 = " + repr( int( shrink * (2**32) ) )
|
||||||
print "expansion factor = " + repr(1/shrink)
|
print "expansion factor = " + repr( 1/shrink )
|
||||||
print ""
|
print ""
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue