
from math import *
from IndiceVerre import *
from Dioptres import *
from pylab import *
n1 = Vide()
n2 = Vide()
n2.negatif()
r = 100
c = -1.0/2000
miroir = Conique(0,c,0.0,n1,n2,r)
sys = SystemeCentre()
sys.ajouter(miroir)
sys.ni.negatif()
sys.matriceTransfert('d')
[Fo,Fi,Ho,Hi] = sys.foyers('d')
focale = Hi.z-Fi.z
            

rAiry = 1.2*588e-6/(2*r)*focale
            

f = FaisceauParalleleMeridien(10,0.0,-2000,r)
sys.refractionFaisceau(f,'d')
figure()
for Rc in f.listeRayons:
    XYZ = Rc.getXYZ(1200)
    plot(XYZ[2],XYZ[0],color='y')
xlabel('z')
ylabel('x') 
grid(True)
            

zi = Fi.z
planImage = PlanImage(zi,r)
sys.ajouter(planImage)
            

from matplotlib.patches import Circle
def spotDiagram(sys,alpha,r,xi):
    f = FaisceauParallele(20,alpha,-100,r)
    sys.refractionFaisceau(f,'d')
    for Rc in f.listeRayons:
        P = Rc.getRayon().P
        plot([P[0]],[P[1]],color='y',marker='.')
    angles = linspace(0,2*pi,100)
    plot(xi+rAiry*cos(angles),rAiry*sin(angles),color='k')
            

figure(figsize=(6,6))
spotDiagram(sys,0.0,r,0)
xlabel('x')
ylabel('y')
grid(True)
scale = 0.04
axis([-scale,scale,-scale,scale])
            

fig=figure(figsize=(6,6))
alpha = 0.005
x = alpha*focale
spotDiagram(sys,alpha,r,x)
xlabel('x')
ylabel('y')
grid(True)
axis([x-scale,x+scale,-scale,scale])
            

fig=figure(figsize=(6,6))
alpha = 0.001
x = alpha*focale
spotDiagram(sys,alpha,r,x)
xlabel('x')
ylabel('y')
grid(True)
axis([x-scale,x+scale,-scale,scale])
            

cat = CatalogueVerre()
def systemeBarlow(c1,c2,d):
    nb = cat.verre['N-BK7']
    na = cat.verre['F5']
    na.negatif() 
    nb.negatif()
    ra = 10.0
    z = -1000.0+d
    e1 = 3.0
    e2 = 3.0
    c0 = -5e-3
    dioptreA = Spherique(z,c0,n2,na,ra)
    dioptreB = Spherique(z-e1,c2,na,nb,ra)
    dioptreC = Spherique(z-e1-e2,c1,nb,n2,ra)
    sys = SystemeCentre()
    sys.ajouter(miroir)
    sys.ajouter(dioptreA)  
    sys.ajouter(dioptreB)
    sys.ajouter(dioptreC)
    barlow = SystemeCentre()
    barlow.ajouter(dioptreA)
    barlow.ajouter(dioptreB)
    barlow.ajouter(dioptreC)
    return [barlow,sys]
    

c1 = -25e-3
d = 60
c2List = []
y = []
N=10
for k in range(N):
    c2 = 10e-3+20e-3/N*k
    c2List.append(c2)
    [barlow,sys] = systemeBarlow(c1,c2,d)
    sys.ni.negatif()
    sys.matriceTransfert('F')
    [Fo,Fi,Ho,Hi] = sys.foyers('F') 
    z = Fi.z
    sys.matriceTransfert('C')
    [Fo,Fi,Ho,Hi] = sys.foyers('C')
    y.append(Fi.z-z)
figure()
plot(c2List,y,color='r')
xlabel('c2')
ylabel('ACL')
grid(True)
axis([0.013,0.015,-0.1,0.1])
    

c2 = 0.0143
    

[barlow,sys] = systemeBarlow(c1,c2,d)    
sys.ni.negatif()
sys.matriceTransfert('d')
[Fo,Fi,Ho,Hi] = sys.foyers('d') 
            

sys.matriceTransfert('F')
[Fo,Fi,Ho,Hi] = sys.foyers('F') 
z = Fi.z
sys.matriceTransfert('d')
[Fo,Fi,Ho,Hi] = sys.foyers('d')
acl2 = Fi.z - z
            

barlow.ni.negatif()
barlow.no.negatif()
barlow.matriceTransfert('d')
[Fo,Fi,Ho,Hi] = barlow.foyers('d')
focaleBarlow = Fi.z - Hi.z
PObjet = Position(-1000.0) # objet au foyer primaire
g = barlow.grandissement(PObjet,'d')
            

f = FaisceauParalleleMeridien(10,0.0,-500,r)
sys.refractionFaisceau(f,'d')
figure()
for Rc in f.listeRayons:
    XYZ = Rc.getXYZ(1200)
    plot(XYZ[2],XYZ[0],color='y')
sys.tracerProfils(20,'k')
xlabel('z')
ylabel('x')
grid(True)
axis([-1100,-900,-20,20])
            

axis([-1049,-1048,-0.1,0.1])
            

zi = -1048.6
planImage = PlanImage(zi,r)
sys.ajouter(planImage)
figure(figsize=(6,6))
alpha = 0.0
spotDiagram(sys,alpha,r,0.0)
xlabel('x')
ylabel('y')
grid(True)
scale = 0.04
axis([-scale,scale,-scale,scale])
            

figure(figsize=(6,6))
alpha = 0.005
x = 9.325
spotDiagram(sys,alpha,r,x)
xlabel('x')
ylabel('y') 
grid(True) 
scale = 0.04
axis([x-scale,x+scale,-scale,scale])
            

def systemeRoss(d):
    n = cat.verre['N-BK7']
    n.negatif()
    r = 25
    z = -1000.0+d
    dioptreA = Spherique(z,-1.0/93.21,n2,n,r)
    dioptreB = Spherique(z-2.01,-1.0/47.31,n,n2,r)
    dioptreC = Spherique(z-2.01-5.70,-1.0/215.52,n2,n,r)
    dioptreD = Spherique(z-2.01-5.70-5.28,1.0/173.50,n,n2,r)
    sys = SystemeCentre()
    sys.ajouterListe([miroir,dioptreA,dioptreB,dioptreC,dioptreD])
    ross = SystemeCentre()
    ross.ajouterListe([dioptreA,dioptreB,dioptreC,dioptreD])
    return [ross,sys]
                

[ross,sys] = systemeRoss(61.0)
f = FaisceauParalleleMeridien(10,0.0,-500,r) 
sys.refractionFaisceau(f,'d')
figure()
for Rc in f.listeRayons:
    XYZ = Rc.getXYZ(1200)
    plot(XYZ[2],XYZ[0],color='y')
sys.tracerProfils(20,'k')
xlabel('z')
ylabel('x')
grid(True)
axis([-1050,-900,-20,20])
                

axis([-1005.5,-1004.5,-0.1,0.1])
                

zi = -1005.29
planImage = PlanImage(zi,r)
sys.ajouter(planImage)
figure(figsize=(6,6))
alpha = 0.0
spotDiagram(sys,alpha,r,0.0)
xlabel('x')
ylabel('y')
grid(True)
scale = 0.04
axis([-scale,scale,-scale,scale])
                

figure(figsize=(6,6))
alpha = 0.005
x = 5.11
spotDiagram(sys,alpha,r,x)
xlabel('x')
ylabel('y') 
grid(True) 
scale = 0.04
axis([x-scale,x+scale,-scale,scale])
            
