Пример #1
0
def optimiselens(beam, n):
    """Find the best two lens curvatures to produce the minimum rms value, with
	n = number of curvature increments between -1 and 1, and beam = input beam"""
    rms = []
    outputplane = rt.OutputPlane(200)
    for i in np.linspace(-1.0, 1.0, n):
        for x in np.linspace(-1.0, 1.0, n):
            lens1 = rt.SphericalRefraction(100.0, i, 1.0, 1.5168, 29.74944)
            lens2 = rt.SphericalRefraction(105.0, x, 1.5168, 1.0, 29.74944)
            beam.trace2(lens1, lens2, outputplane)
            rms.append([i, x, beam.rms(outputplane)])
    m = MinList(rms, [0, 0, 100])
    print "lens 1 curvature = %s, lens 2 curvature = %s, rms = %s" % (
        m[0], m[1], m[1])
Пример #2
0
def propagateray(ray, lens_type, lens_curvature, lens_2nd_curvature = 0, word = "Yes"):
    """
    This function propagates the ray towards the lens. The RMS deviation at the focal point and the new ray object is returned.
    """
    if lens_type == 0:
        lens = rt.SphericalRefraction(lens_z0, lens_aperture, lens_curvature, surrounding_refractive_index, lens_refractive_index, word)    
    elif lens_type == 1:
        lens = rt.PlanoConvex(lens_z0, lens_depth, lens_curvature, surrounding_refractive_index, lens_refractive_index, word)
    elif lens_type == 2:
        lens = rt.BiSurface(lens_z0, lens_aperture, lens_depth, lens_curvature, lens_2nd_curvature, surrounding_refractive_index, lens_refractive_index, word)
    temp = ray.propagate(lens)
    if temp is None:
        return -1, -1
    if focal_method == 0:
        focal_position = ray.focalpoint_std()
    elif focal_method == 1:
        focal_position = ray.focalpoint_maxlength()
    if focal_position is None:
        output = rt.OutputPlane((lens_z0+lens_depth)*2.5)
        print "No focal point outside of the lens"
    else:
        output = rt.OutputPlane(focal_position[-1])
    temp = ray.propagate(output)
    if temp is None:
        return -1, -1
    rms = ray.rms_deviation("output")
    return rms, ray
Пример #3
0
def Lens_trial(c,z0,z1,rmax,z0_out):
    """ This method produces a function that returns an rms value.
        The rms value will be minimised using an numerical optimisation function.
        c is a list with the curvatures of the two refractive surface elements.
        z0 is the intecept of the first spherical refraction surface with the z axis
        while z1 is the intercept for the second surface. rmax is the beam radius.
        z0_out is the position of the output plane.
            """
    test_rays = Bundle.bundle(n=5 , rmax=5  , m=4, initial_z = 0, direction = [0,0,1])
    Surface1 = rt.SphericalRefraction(100,c[0],1,1.5168,50)
    Surface2 = rt.SphericalRefraction(155,c[1],1.5168,1,50)
    Output = rt.OutputPlane(z0_out)
    for ray in test_rays:
        Surface1.propagate_ray(ray)
        Surface2.propagate_ray(ray)
        Output.propagate_ray(ray)
    rms = root_mean_square(test_rays)
    return rms
Пример #4
0
    def append(self):
        """ Takes each set of spherical refraction surface element parameters
        and creates a list of the corresponding surface elements """
        para = self.__para
        list_of_elements = []

        for i in para:
            ith_element = rt.SphericalRefraction(i[0],i[1],i[2],i[3],i[4])
            list_of_elements.append(ith_element)
        return list_of_elements
Пример #5
0
 def __init__(self, z, curve, n1, n2, aperture, separation):
     type = "convex-plano lens"
     self.z = z
     self.curve = curve
     self.n1 = n1
     self.n2 = n2
     self.aperture = aperture
     self.separation = separation
     self.left = rt.SphericalRefraction(z_0=z,
                                        curve=curve,
                                        n1=n1,
                                        n2=n2,
                                        aperture=aperture)
     self.right = rt.SphericalRefraction(z_0=z + separation,
                                         curve=-curve,
                                         n1=n2,
                                         n2=n1,
                                         aperture=aperture)
     rt.OpticalElement.__init__(self, type, n1, n2, curve)
Пример #6
0
def work(n, rmax, m):
    q=0
    u=0
    for ray in bundlerays(n, rmax, m):
        sphere = raytracer.SphericalRefraction(2.,0.03,1.,1.5,20.)
        H=raytracer.OutputPlane(150)
        sphere.propagate(ray)
        H.propagate(ray)
        k = ray.vertices()
        tmp = zip(*k)
        pyl.plot(tmp[2],tmp[0])
        #pyl.plot(tmp[1][-1],tmp[0][-1],'bo')
        #pyl.plot(tmp[1][0],tmp[0][0],'ro')
        q += tmp[0][-1]**2 + tmp[1][-1]**2
        u +=1 
Пример #7
0
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Fri Dec 16 01:01:42 2016

@author: barnabysandeford
"""
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import raytracer as rt
reload(rt)

s = rt.SphericalRefraction(100, 0.03, 1.0, 1.5, (1 / 0.03))
# Finding the paraxial focal point of the spherical optical element
F = rt.focal_point1(s)
# The output plane is automatically placed at the paraxial focal point of "s".
p = rt.OutputPlane(F, 10000)


def zx_plot(n, rmax, m):
    """Creates a z-x plot of a bundle of rays propogated through "s".
    
       Parameters
       ----------
       n:    integer_type
             The number of concentric circles of rays within the
             distribution.
       rmax: float_type
             The maximum radius of the distribution of rays.
       m:    integer_type
             The rate at which the number of rays per concentric circle
Пример #8
0
"""Module to implement the raytracer model and propagate a bundle of rays through different refractive media."""

import matplotlib.pyplot as plt
import raytracer as rt
import genpolar as gp
import numpy as np

#Lens definitions for first and second orientations respectively

SR1 = rt.SphericalRefraction(100.0, 0ol0o, 1.0, 1.5168, 10.0) #plane surface first
SR2 = rt.SphericalRefraction(105.0, -0.02, 1.5168, 1.0, 10.0) #negative curvature

SR3 = rt.SphericalRefraction(100.0, 0.02, 1.0, 1.5168, 10.0) #positive curvature
SR4 = rt.SphericalRefraction(105.0, 0, 1.5168, 1.0, 10.0) #plane surface second


def findzintercept(lens1,lens2):
    """Finds intersection point of ray with z-axis"""

    TR = rt.Ray([0.1,0.1,80],[0.0,0.0,1.0]) #test ray close to z-axis
    lens1.propagate_ray(TR)
    lens2.propagate_ray(TR)
    ratio = -(TR._p[0])/(TR._k[0])
    intercept = TR._p + (ratio*TR._k)
    return intercept


def findrms(raylist):
    """Finds rms value of a bundle of rays"""

    sum = 0
Пример #9
0
Author: Cara
Created: 30/10/19 10:52

A test for a concave spherical refracting surface.
"""

import raytracer as rt
from raybundle import Bundle
import matplotlib.pyplot as plt
import scipy as sp
from mpl_toolkits import mplot3d

# create a spherical surface and an output plane at the paraxial focus
surface = rt.SphericalRefraction(z_0=100,
                                 curve=-0.03,
                                 n1=1.0,
                                 n2=1.5,
                                 aperture=30.)
# a concave lens only has an imaginary focus behind it
output = rt.OutputPlane(z_1=250)

# creates a collimated beam with (radius, line density around outer circumference)
beam = Bundle(2, 3)

fig = plt.figure()
ax = plt.axes()
"""
origins = beam.con_circs()

# get points of rays into individual arrays and plot them
for o in origins:
Пример #10
0
"""
Modelling a planoconvex singlet lens.
"""
import numpy as np
import matplotlib.pyplot as plt
import raytracer as rt

# Defining the planoconvex lens with the curved surface first, with a 
# refractive index of 1.5168.
convex = rt.SphericalRefraction(100, 0.02, 1.0, 1.5168, 21.8 )
plane1 = rt.SphericalRefraction(105, 0, 1.5168, 1.0, 21.8)
# Defining the planoconvex lens with the curved surface last.
concave = rt.SphericalRefraction(105, -0.02, 1.5168, 1.0, 21.8 )
plane2 = rt.SphericalRefraction(100, 0, 1.0, 1.5168, 21.8)
# Defining the wavelength of the incident rays.
L = (588*10**(-9))

def zxPlot(n, rmax, m , lens1, lens2):
    """ Creates a plot in the z-x plane of a bundle of rays through two optical
        elements.  The optical elements can be chosen such that they form
        planoconvex lenses.
        
        Parameters
        ----------
        n:    integer_type
              The number of concentric circles of rays within the
              distribution.
       rmax:  float_type
              The maximum radius of the distribution of rays.
       m:     integer_type
              The rate at which the number of rays per concentric circle
Пример #11
0
import raytracer

s = raytracer.SphericalRefraction(z_0=1, curve=0.25, n1=1, n2=0.8, aperture=3)
r = raytracer.Ray(pos=[1., 2., 3.], direc=[1., 2., 3.])
print(s.intercept(r))

s2 = raytracer.SphericalRefraction(z_0=0, curve=0.8, n1=1, n2=0.8, aperture=10)
r2 = raytracer.Ray(pos=[4., 5., 6.], direc=[1., 2., 3.])
print(s2.intercept(r2))
# imag result, filtered as expected

s3 = raytracer.SphericalRefraction(z_0=1, curve=0.4, n1=1, n2=0.8, aperture=5)
r3 = raytracer.Ray(pos=[7., 8., 9.], direc=[4., 0., 1.])
print(s3.intercept(r3))
# imag result, filtered as expected

# Would be much easier to see these intercepts are in the right place once plotting multiple rays