fresn.py :  » Business-Application » ThanCad » thancad-0.0.9 » p_gmath » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Business Application » ThanCad 
ThanCad » thancad 0.0.9 » p_gmath » fresn.py
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()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.