import sys
from math import sqrt,cos,sin,pi
from varcon import PI05,PIR
############################################################################
############################################################################
#MODULE LEVEL ROUTINES
#============================================================================
def fresnel(x):
# EPS=6.e-8; MAXIT=100; FPMIN=1.e-30; XMIN=1.5
# PIBY2=pi * 0.5
# true = 1
ax=abs(x)
if ax < sqrt(FPMIN):
s=0.
c=ax
if x < 0.: c=-c; s=-s
return s, c
elif ax <= XMIN:
sum=0.
sums=0.
sumc=ax
sign=1.
fact=PI05*ax*ax
odd = True
term=ax
n=3
for k in range(1, MAXIT+1):
term=term*fact/k
sum=sum+sign*term/n
test=abs(sum)*EPS
if odd:
sign=-sign
sums=sum
sum=sumc
else:
sumc=sum
sum=sums
if term < test:
s=sums
c=sumc
if x < 0.: c=-c; s=-s
return s, c
odd = not odd
n += 2
print 'series failed in fresnel'
return None
else:
pix2=pi*ax*ax
b=complex(1.,-pix2)
cc=1./FPMIN
d=1./b
h=d
n=-1
for k in range(2,MAXIT+1):
n += 2
a=-n*(n+1)
b=b+4.
d=1./(a*d+b)
cc=b+a/cc
del1=cc*d
h=h*del1
# if absc(del1-1.) < EPS:
if abs(del1.real-1.) + abs(del1.imag) < EPS:
h=h*complex(ax,-ax)
cs=complex(.5,.5)*(1.-complex(cos(.5*pix2),sin(.5*pix2))*h)
c=cs.real
s=cs.imag
if x < 0.: c=-c; s=-s
return s, c
print 'cf failed in fresnel'
return None
#============================================================================
def klotXy(A, L, pr=1):
"Calculates xy coordinates of klotoidis of parameter A at distance L from start."
s, c = fresnel(L / A / PIR)
apir = A * PIR
return (apir*c, apir*s*pr)
#============================================================================
def dok():
from p_gchart import ThanChart,vis
ch = ThanChart()
al = 40.83
r = 30.0
a = sqrt(al*r)
xth = 0.0; xx = []; yy = []
for i in range(250):
xth = xth + 1.0
v = klotXy(a, xth, 1.0)
# print "%15.3f%15.3f%15.3f" % (xth, v[0], v[1])
xx.append(v[0]); yy.append(v[1])
ch.curveAdd(xx, yy, style="christar", color="magenta", fill="yellow", size=10)
ch.curveAdd(xx, yy, style="continuous", color="blue", size=5)
vis(ch)
############################################################################
############################################################################
#MODULE LEVEL CODE: THIS IS EXECUTED ONLY ONCE
#===========================================================================
#-------define constants
EPS=6.e-8; MAXIT=100; FPMIN=1.e-30; XMIN=1.5
if __name__ == "__main__": dok()
|