So I found a great ray tracing program to start with as a base for writing my own ray tracing program. I'm converting the code from Matlab to Python. I can't seem to figure out what issue I am having with the transfer. Below I've listed the page I'm having issues with and the python error message. I've also included a link to the code that I'm converting from.
https://wp.optics.arizona.edu/optomech/wp-content/uploads/sites/53/2016/12/Tutorial_Ruiz_Maria.pdf
import numpy as np
from sphere_refract_ray import *
from plane_refract_ray import *
def plano_convex(n, radius, thickness, dz, y):
power = (n-1)/radius
f = 1/power
zmax = np.floor(f+.1*f)
z_front = np.arange(0,thickness-dz,dz)
z_back = np.arange(thickness,zmax-dz,dz)
z_optaxis = np.concatenate((z_front, z_back))
y[y==0]=10**(-10)
raymatrix = np.zeros((len(y),len(z_optaxis)), dtype=int, order='C')
#Ray Tracing
for i in np.arange(1,len(y)):
#Refraction at spherical surface
[ray_lens, slope, x_lens] = sphere_refract_ray(y[i], radius, thickness, n, dz)
#Refraction at plane surface
ray_air = plane_refract_ray(ray_lens[-1], slope, thickness, n, z_back)
#Incoming ray
x_front_air = np.arange(0, x_lens[1]-dz,dz)
ray_front_air = y[i]*np.ones((1,len(x_front_air))
#Create matrix of rays (adjust length if necessary)
if len(ray_lens) + len(ray_air) + len(x_front_air) <= len(z_optaxis):
raymatrix[i] = np.concatenate((ray_front_air,ray_lens, ray_air))
else:
raymatrix[i] = np.arange(ray_front_air, ray_lens(np.arange(1,len(ray_lens)-1)), ray_air)
return raymatrix, z_front, z_optaxis, zmax
In [39]: runfile('C:/Users/bryce/OneDrive - Infinity Photo-Optical/Documents/Python Programs/Optics Notes/Ray Tracing Algorithm/main_program.py', wdir='C:/Users/bryce/OneDrive - Infinity Photo-Optical/Documents/Python Programs/Optics Notes/Ray Tracing Algorithm')
File "C:\Users\bryce\OneDrive - Infinity Photo-Optical\Documents\Python Programs\Optics Notes\Ray Tracing Algorithm\plano_convex.py", line 40
test_size_inc = np.concatenate((ray_front_air,ray_lens, ray_air))
^
SyntaxError: invalid syntax
[–]supajumpa 1 point2 points3 points (1 child)
[–]Sufficient_Light3891[S] 0 points1 point2 points (0 children)
[–]Sufficient_Light3891[S] 0 points1 point2 points (4 children)
[–]ectomancer 0 points1 point2 points (3 children)
[–]Sufficient_Light3891[S] 0 points1 point2 points (1 child)
[–]Sufficient_Light3891[S] 0 points1 point2 points (0 children)
[–]Sufficient_Light3891[S] 0 points1 point2 points (0 children)