|
| 1 | + |
| 2 | +# External imports |
| 3 | +# import matplotlib as mpl |
| 4 | +# from mpl_toolkits.mplot3d import Axes3D |
| 5 | +import matplotlib.pyplot as plt |
| 6 | +import numpy as np |
| 7 | + |
| 8 | +# Raysect imports |
| 9 | +from raysect.optical import World, translate, rotate, Point3D, d65_white, Ray, Vector3D |
| 10 | +from raysect.optical.material.absorber import AbsorbingSurface |
| 11 | +from raysect.optical.library import schott |
| 12 | +from raysect.primitive import Sphere, Box |
| 13 | +from raysect.optical.loggingray import LoggingRay |
| 14 | +from raysect.primitive.lens.spherical import * |
| 15 | + |
| 16 | + |
| 17 | +world = World() |
| 18 | + |
| 19 | +# Create a glass BiConvex lens we want to study |
| 20 | +lens_glass = schott("N-BK7") |
| 21 | +lens_glass.transmission_only = True |
| 22 | +lens = BiConvex(0.0254, 0.0052, 0.0506, 0.0506, parent=world, material=lens_glass) |
| 23 | +lens.meta['viz-color'] = (66/255, 188/255, 244/255) |
| 24 | +lens.meta['viz-opacity'] = 0.5 |
| 25 | + |
| 26 | +# lens.meta['viz']['color'] = (66/255, 188/255, 244/255) |
| 27 | +# lens.meta['viz']['opacity'] = 0.5 |
| 28 | + |
| 29 | +# Create a target plane behind the lens. |
| 30 | +target = Box(lower=Point3D(-0.05, -0.05, -0), upper=Point3D(0.05, 0.05, 0), material=AbsorbingSurface(), |
| 31 | + transform=translate(0, 0, 0.1), parent=world) |
| 32 | +target.meta['viz-color'] = (224/255, 100/255, 17/255) |
| 33 | + |
| 34 | + |
| 35 | +# for each sample direction trace a logging ray and plot the ray trajectory |
| 36 | +plt.ion() |
| 37 | +fig = plt.figure() |
| 38 | +# ax = fig.gca(projection='3d') |
| 39 | + |
| 40 | +# for u in np.linspace(-0.006, 0.006, 5): |
| 41 | +for v in np.linspace(-0.012, 0.012, 11): |
| 42 | + |
| 43 | + start = Point3D(v, 0, -0.05) |
| 44 | + log_ray = LoggingRay(start, Vector3D(0, 0, 1)) |
| 45 | + log_ray.trace(world) |
| 46 | + |
| 47 | + vertices = log_ray.path_vertices |
| 48 | + |
| 49 | + p = [(v.x, v.z) for v in vertices] |
| 50 | + p = np.array(p) |
| 51 | + |
| 52 | + plt.plot(p[:, 0], p[:, 1], 'k-') |
| 53 | + plt.plot(p[:, 0], p[:, 1], 'r.') |
| 54 | + |
| 55 | + |
| 56 | +from raysect_mayavi import visualise_scenegraph |
| 57 | +from mayavi import mlab |
| 58 | + |
| 59 | + |
| 60 | +visualise_scenegraph(world) |
| 61 | + |
| 62 | + |
| 63 | +for v in np.linspace(-0.012, 0.012, 11): |
| 64 | + |
| 65 | + start = Point3D(v, 0, -0.05) |
| 66 | + log_ray = LoggingRay(start, Vector3D(0, 0, 1)) |
| 67 | + log_ray.trace(world) |
| 68 | + |
| 69 | + vertices = log_ray.path_vertices |
| 70 | + |
| 71 | + p = [(v.x, v.y, v.z) for v in vertices] |
| 72 | + p = np.array(p) |
| 73 | + |
| 74 | + mlab.plot3d(p[:, 0], p[:, 1], p[:, 2], tube_radius=0.0005) |
| 75 | + |
| 76 | +plt.ioff() |
| 77 | +plt.show() |
0 commit comments