Skip to main content
Question

trace vignetting surface number using ZOS-API

  • January 11, 2024
  • 1 reply
  • 66 views

redbottle

Hi All,

 

I know if using ZPL , RAVY() is used to trace vignetting surface number. if I need to do that using API, how to implement it? Much appreciated for the help!

1 reply

David.Nguyen
Luminary
Forum|alt.badge.img+2
  • Luminary
  • 1097 replies
  • January 12, 2024

Hi @redbottle,

 

The ZOSAPI has an equivalent vignetteCode in the various raytraces. The vignetteCode is either 0 if the ray is not vignetted or the surface number at which the ray is clipped otherwise. Here is the Syntax Help for the normalized unpolarized raytrace:

You were not specific in your question, so I’m showing a basic example with the batch raytrace and a normalized unpolarized raytrace assuming you trace a single ray to the last surface of your system:

from System import Enum, Int32, Double


# Required to read the raytrace data
sysInt = Int32(1)
sysDbl = Double(1.0)

# Open batch raytrace tool
batchRayTrace = TheSystem.Tools.OpenBatchRayTrace()

# Normalized unpolarized raytrace parameters
maxRays = 1
raysType = ZOSAPI.Tools.RayTrace.RaysType.Real
toSurface = TheSystem.LDE.NumberOfSurfaces - 1

# Create a normalized unpolarized raytrace
normUnpol = batchRayTrace.CreateNormUnpol(maxRays, raysType, toSurface)

# Clear previous data (if necessary)
normUnpol.ClearData()

# Single ray parameters
waveNum = 1
Hx = 0.0
Hy = 0.0
Px = 0.0
Py = 1.0
opdMode = Enum.Parse(ZOSAPI.Tools.RayTrace.OPDMode, "None")

# Add a single ray to the raytrace
normUnpol.AddRay(waveNum, Hx, Hy, Px, Py, opdMode)

# Run the raytrace
batchRayTrace.RunAndWaitForCompletion()

# Analyze the raytrace
if normUnpol.HasResultData:
    normUnpol.StartReadingResults()
    rayData = normUnpol.ReadNextResult(sysInt, sysInt, sysInt,
                                       sysDbl, sysDbl, sysDbl,
                                       sysDbl, sysDbl, sysDbl,
                                       sysDbl, sysDbl, sysDbl,
                                       sysDbl, sysDbl)
    # Check if success and no errors
    if rayData[0] and rayData[2] == 0:
        # Print vignetting status
        if rayData[3] == 0:
            print("Ray not vignetted")
        else:
            print("Ray vignetted at surface {0}".format(rayData[3]))

# Close raytrace tool
batchRayTrace.Close()

Note that this is Python but the syntax should be quite similar in MATLAB. Have a look at the MATLAB implementation of Example 22 in the Syntax Help File if necessary.

Have a look at those articles as well:

https://support.zemax.com/hc/en-us/articles/1500005577222-ZOS-API-using-MATLAB

https://support.zemax.com/hc/en-us/articles/1500005576882-Batch-Processing-of-Ray-Trace-Data-using-ZOS-API-in-MATLAB-or-Python

I hope this helps. Any other question, let me know. Take care,

 

David


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings