Using ZOP-API to trace a set of rays through a non sequential system

  • 17 May 2024
  • 1 reply

Hello there Zemax community,

In connection to the post 

I was wondering if this tool would be the right tool for tracing a sequence of rays in non sequential mode via python.

So far, I have tried using this single ray tracing approach in order to trace a sequence of rays from my source through an optical system which includes two freeform surfaces. This is how my system looks like:



At the end, what I want to do, is to trace specific ray directions originating from the source location (the point at the left) and extract the ray directions after refraction from the first surface towards the second surface.

However, when I try to do this with the single ray tracing tool, for some reason, the tool always traces the same on axis ray and I cannot get any information about the other rays directions.

This is an example of the code that I am using (I am using the python interface to the ZOP-API):

nscsrt = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.NSCSingleRayTrace)
nscsrt_settings = nscsrt.GetSettings()
nscsrt_settings.RaySourceX = 0.0
nscsrt_settings.RaySourceY = 0.0
nscsrt_settings.RaySourceZ = 0.0
nscsrt_settings.RefObject = 2

nscsrt_settings.SplitNSCRays = False
nscsrt_settings.ScatterNSCRays = False
nscsrt_settings.UsePolarization = False

for i in range(0,100,1):
nscsrt_settings.RaySourceL = I_dir[0, i]
nscsrt_settings.RaySourceM = I_dir[1, i]
nscsrt_settings.RaySourceN = I_dir[2, i]

nscsrt_data = nscsrt.GetResults().NSCSingleRayTraceData

data_segment1 = nscsrt_data.ReadSegmentFull(1)

data_segment2 = nscsrt_data.ReadSegmentFull(2)

data_segment3 = nscsrt_data.ReadSegmentFull(3)

s1_dirs = np.stack((l_s1,m_s1,n_s1),axis=0)
s2_dirs = np.stack((l_s2,m_s2,n_s2),axis=0)
s3_dirs = np.stack((l_s3,m_s3,n_s3),axis=0)

The array I_dir is just an array containing unit vectors (l,m,n) that represent the specific directions for the rays  I am interested in. These ray vectors are simply obtained from a stereographic projection of a half sphere (this means, these ray directions are normal to the surface of the sphere)

Finally, this is plot of the results that I obtain from the single ray tracing analysis:


In this case, the blue dots correspond to the x and y components of the unit direction vectors that I am interested in tracing. The orange dot at the center corresponds to the result from the single ray tracing analaysis. As you can see, no matter which ray direction I set, it seems that the analysis is always performed for the on axis ray.

Any idea about what could be happening here? Maybe you have a suggestion on what do do? Could it be possible to trace all of these rays simultaneously and obtain the output ray directions that I need? Is this supported by the API?

In advance, thanks for the help and comments.



1 reply

Although I am currently having trouble to get my data extracted from a ZRD-File, I suggest you put I_dir into a source file. Then trace the whole system (Analyze → Ray Trace → Clear and Trace with “save rays” checked) and save to a ray database file.
Possibly, this has to be read with ZOSAPI.Tools.RayTrace.IZRDReader, because Ansys is boarding up all windows towards external tools. But IZRDReader should be feasible. And this way you can also visualize all rays with the 3d-viewers or look at the data with the “ray database viewer”.
Be aware that the “source file”-souce has parameters “Layout Rays” and “Analysis Rays”. Only up to Analysis rays gets into the ray-database file. And only Layout Rays are visible in the viewers.