コード例 #1
0
# IPython log file

import numpy as np
import pylab as pl
import raytracerfinal as rtf
testray = rtf.ray([0,0.1,0],[0,0,1])
surf1 = rtf.SphericalRefraction(20,0,1,1.5168,5.5)
surf2 = rtf.SphericalRefraction(25,-0.02,1.5168,1,5.5)
out = rtf.OutputPlane(75)
# determination of paraxial focus
surf1.propagate_ray(testray)
surf2.propagate_ray(testray)
out.propagate_ray(testray)
get_ipython().magic(u'matplotlib qt')
pl.plot(testray.z(),testray.y())
pl.grid()
pl.xlabel("z")
pl.ylabel("y")
# output plane not far enough, set z = 160
out = rtf.OutputPlane(160)
testray = rtf.ray([0,0.1,0],[0,0,1])
surf1.propagate_ray(testray)
surf2.propagate_ray(testray)
out.propagate_ray(testray)
pl.figure()
pl.plot(testray.z(),testray.y())
pl.grid()
pl.xlabel("z")
pl.ylabel("y")
# paraxial focus at z ~ 121.75
out = rtf.OutputPlane(121.75)
コード例 #2
0
import raytracerfinal as rtf

# Test 1: through surface 1 surf1
newray = rtf.ray([0,0,-10-1./0.3],[0,0,1])
surf = rtf.SphericalRefraction(-1./0.3, 0.3, 0.1, 0.3, 20.)
surf.propagate_ray(newray)
print newray.vertices() # new point added
print newray.p() # new point replaced old
print newray.k() # remains the same

# Test 2: through a second surface surf2
surf2 = rtf.SphericalRefraction(10,0.2,1.5,1,2)
surf2.propagate_ray(newray)
print newray.vertices() # another point added
print newray.p()
print newray.k()

# Test 3: through surface 1 again (not possible!)
surf.propagate_ray(newray)
print newray._term # True --> terminated now

# Test 4: propagate parallel to surface
newray = rtf.ray([0,-10,-1./0.3],[0,1,0])
surf = rtf.SphericalRefraction(-1./0.3, 0.3, 1, 1.5, 1.)
surf.propagate_ray(newray)
print newray.vertices() # y-coord of new point ~ 0
print newray.k() # compare with Task 5 test

# Test 5: total internal reflection
newray = rtf.ray([0,-10,0],[0,1,1])
surf2.propagate_ray(newray)
コード例 #3
0
ファイル: task8.py プロジェクト: adrielyeung/ray-tracer
import raytracerfinal as rtf
import pylab as pl

surf1 = rtf.SphericalRefraction(19.9, 0.03, 1, 1.5, 3)
surf2 = rtf.SphericalRefraction(20.1, -0.03, 1.5, 1, 3)
ray1 = rtf.ray([0, 1, 0], [0, 0, 1])
ray2 = rtf.ray([0, 0, 0], [0, 0, 1])
ray3 = rtf.ray([0, -1, 0], [0, 0, 1])
out = rtf.OutputPlane(53.2)
surf1.propagate_ray(ray1)
surf2.propagate_ray(ray1)
out.propagate_ray(ray1)
surf1.propagate_ray(ray2)
surf2.propagate_ray(ray2)
out.propagate_ray(ray2)
surf1.propagate_ray(ray3)
surf2.propagate_ray(ray3)
out.propagate_ray(ray3)
print ray1.p()
print ray1.vertices()
print ray1.k()
# 4 points obtained as expected

# try plotting path of rays, see p. 39 for diagram
get_ipython().magic(u'matplotlib qt')
pl.figure()
pl.plot(ray1.z(), ray1.y())
pl.plot(ray2.z(), ray2.y())
pl.plot(ray3.z(), ray3.y())
pl.xlabel("z")
pl.ylabel("y")
コード例 #4
0
ファイル: task4.py プロジェクト: adrielyeung/ray-tracer
import raytracerfinal as rtf
import numpy as np

# 1D case
newray = rtf.ray([0, 0, -10 - 1. / 0.3],
                 [0, 0, 1])  # distance = 10 away from lens
surf = rtf.SphericalRefraction(-1. / 0.3, 0.3, 0.1, 0.3,
                               20.)  # centred at origin
print surf.intercept(newray)

# 2D case
newray2 = rtf.ray(
    [0, -9, -10 - 1. / 0.3],
    [0, 1, 1])  # should hit the surface a bit higher than the z-axis
print surf.intercept(newray2)
print np.linalg.norm(surf.intercept(newray2))