from optics3d import Ray, Mirror
import matplotlib.pyplot as plt
from general import set_axes_equal
plt.close("all")

mir_center = np.array([0, 50, 0])
mir_normal = np.array([0, -1, 0])
mir_tangent = np.array([0, 0, 1])

mirror1 = Mirror(mir_center, normal=mir_normal, shape="rectangular_flat", tangent=mir_tangent, h=50, w=50)
Optic_list = []
Optic_list.append(mirror1)

max_ray_run_distance = 150

ray = Ray(np.array([0, 0, 0]), np.array([0, 1, 0]), wavelength=532, print_trajectory=True)
Ray_list = []
Ray_list.append(ray)


for ray in Ray_list:
    ray.run(max_distance=max_ray_run_distance, optic_list=Optic_list)


# 3d plots
fig = plt.figure()
ax = plt.axes(projection='3d')
# ax.set_aspect("equal")
for optic in Optic_list:
    optic.draw(ax, view="3d")
for ray in Ray_list:
Ejemplo n.º 2
0
print(f"test_index_of_world = {test_index_of_world}")
print(f"test_index_of_optic = {test_index_of_optic}")

max_ray_run_distance = 550

x_start = [0]
y_start = [0]
z_start = np.linspace(-25.4 / 4, 25.4 / 4, 21)

Ray_list = []
for x_val in x_start:
    for y_val in y_start:
        for z_val in z_start:
            Ray_list.append(
                Ray(np.array([x_val, y_val, z_val]),
                    np.array([0, 1, 0]),
                    wavelength=532,
                    print_trajectory=False))

FF_radius = max_ray_run_distance - 100
FF_center = np.array([0, y_backprinciple, 0])
Ray_list = add_faerie_fire_rays(Ray_list, FF_radius, FF_center)

for ray in Ray_list:
    ray.run(max_distance=max_ray_run_distance, optic_list=Optic_list)

# 2d plots

fig = plt.figure()
ax = plt.axes()
for ray in Ray_list:
    ray_history = ray.get_plot_repr()
Ejemplo n.º 3
0
Optic_list.append(lens1)
Optic_list.append(detector1)

max_ray_run_distance = 150

Ray_list = []
origins, dirs, waves = image_rays(0,
                                  size=object_size,
                                  angle=image_half_angle,
                                  x_res=5,
                                  z_res=5,
                                  angle_res=3)
for ix, origin in enumerate(origins):
    Ray_list.append(
        Ray(origins[ix],
            dirs[ix],
            wavelength=waves[ix],
            print_trajectory=False))

for ray in Ray_list:
    ray.run(max_distance=max_ray_run_distance, optic_list=Optic_list)

# 2d plots

fig = plt.figure()
ax = plt.axes()
for ray in Ray_list:
    ray_history = ray.get_plot_repr()
    ax.plot(ray_history[:, 1], ray_history[:, 2], "-b")
plt.grid(True)
plt.axis("equal")
Ejemplo n.º 4
0
mirror1_pos = np.array([0, 100, 0])
mirror1_normal = np.array([0, -1, 0])

ray1_pos = np.array([-100, 0, 0])
ray1_direction = np.array([1, 1, 0])
ray2_pos = np.array([-100, 0, 0])
ray2_direction = np.array([1, 0.8, 0])

Optic_list = []
Optic_list.append(
    Mirror(mirror1_pos, normal=mirror1_normal, shape="circular_flat", D=50))

Ray_list = []
Ray_list.append(
    Ray(ray1_pos, ray1_direction, wavelength=532, print_trajectory=False))
Ray_list.append(
    Ray(ray2_pos, ray2_direction, wavelength=532, print_trajectory=True))

for ray in Ray_list:
    ray.run(max_distance=max_ray_run_distance, optic_list=Optic_list)

# 2d plots
fig, axs = plt.subplots(2, 1)
# tangential, x-y plane:
for optic in Optic_list:
    optic.draw(axs[0], view="xy")
for ray in Ray_list:
    ray_history = ray.get_plot_repr()
    axs[0].plot(ray_history[:, 0], ray_history[:, 1], "-r")
# sagittal, x-z plane:
Ejemplo n.º 5
0
mirrorCOMPOUNDtree.getRightChild().insertLeft(mirror2)
mirrorCOMPOUNDtree.getRightChild().insertRight(mirror3)
mirrorCOMPOUND = Compound(mirrorCOMPOUNDtree)
Optic_list = []
Optic_list.append(mirrorCOMPOUND)



Ray_list = []
ray_z = np.linspace(0, 0, 1)
ray_x = np.linspace(-20, 55, 76)
for x_ix, x_val in enumerate(ray_x):
    for z_ix, z_val in enumerate(ray_z):
        ray_pos = np.array([x_val, 0, z_val])
        ray_dir = np.array([0, 1, 0])
        ray = Ray(ray_pos, ray_dir, wavelength=532, print_trajectory=False)
        Ray_list.append(ray)



for ray in Ray_list:
    ray.run(max_distance=max_ray_run_distance, optic_list=Optic_list)


# 3d plots
fig = plt.figure()
ax = plt.axes(projection='3d')
# ax.set_aspect('equal')

for ray in Ray_list:
    ray_history = ray.get_plot_repr()
Ejemplo n.º 6
0
# -*- coding: utf-8 -*-
"""
Created on Sat Dec  8 23:47:35 2018

@author: samuel
"""

import pytest
import numpy as np
from optics3d import Ray
from Shapes.shapes import Rectangle

hit_rays = [
    Ray(np.array([0, 0, 0]),
        np.array([0, 1, 0]),
        wavelength=532,
        print_trajectory=False),
    Ray(np.array([0, 0, 0.499]),
        np.array([0, 1, 0]),
        wavelength=532,
        print_trajectory=False),
]

miss_rays = [
    Ray(np.array([0, 0, 0.501]),
        np.array([0, 1, 0]),
        wavelength=532,
        print_trajectory=False),
]

grating1 = Grating(grating_center,
                   normal=grating_normal,
                   shape="rectangular_flat",
                   tangent=grating_tangent,
                   h=50,
                   w=50,
                   G=G)

Optic_list = []
Optic_list.append(grating1)

max_ray_run_distance = 300

ray1 = Ray(np.array([0, 0, 0]),
           np.array([0, 1, 0]),
           wavelength=400,
           order=1,
           print_trajectory=False)
ray2 = Ray(np.array([0, 0, 0]),
           np.array([0, 1, 0]),
           wavelength=450,
           order=1,
           print_trajectory=False)
ray3 = Ray(np.array([0, 0, 0]),
           np.array([0, 1, 0]),
           wavelength=500,
           order=1,
           print_trajectory=False)
ray4 = Ray(np.array([0, 0, 0]),
           np.array([0, 1, 0]),
           wavelength=550,
Ejemplo n.º 8
0
ray_sweep_xnorm = np.linspace(-0.08, 0.08, 3)
ray_sweep_znorm = np.linspace(-0.09, 0.09, 3)
ray_sweep_z = np.linspace(-5, 5, 11)
ray_sweep_x = np.linspace(-0.03, 0.03, 2)
ray_sweep_wavelength = [350, 530, 600, 610, 700]

Ray_list = []
for xnorm in ray_sweep_xnorm:
    for znorm in ray_sweep_znorm:
        for z in ray_sweep_z:
            for x in ray_sweep_x:
                for wave in ray_sweep_wavelength:
                    Ray_list.append(
                        Ray(np.array([x, 0, z]),
                            np.array([xnorm, 1, znorm]),
                            wavelength=wave,
                            order=1,
                            print_trajectory=False))

for ray in Ray_list:
    ray.run(max_distance=max_ray_run_distance, optic_list=Optic_list)

# 3d plots
fig = plt.figure()
ax = plt.axes(projection='3d')
# ax.set_aspect('equal')
for optic in Optic_list:
    optic.draw(ax, view="3d")
for ray in Ray_list:
    ray_history = ray.get_plot_repr()
    ax.plot(ray_history[:, 0],
Ejemplo n.º 9
0
# -*- coding: utf-8 -*-
"""
Created on Sat Dec  8 23:47:35 2018

@author: samuel
"""

import pytest
import numpy as np
from optics3d import Ray
from Shapes.shapes import Sphere

two_hit_rays = [
    Ray(np.array([0, 0, 0]),
        np.array([0, 1, 0]),
        wavelength=532,
        print_trajectory=False),
]
one_hit_rays = [
    Ray(np.array([0, 10, 0]),
        np.array([0, 1, 0]),
        wavelength=532,
        print_trajectory=False),
    Ray(np.array([0, 10, 0]),
        np.array([0, -1, 0]),
        wavelength=532,
        print_trajectory=False),
    Ray(np.array([0, 10, 0]),
        np.array([0, 0, 1]),
        wavelength=532,
        print_trajectory=False),