**Learn more.**

# What Does "Not Enough Segments Allocated to Trace All Possible Ray Paths" Mean?

Summary:

- Not Enough Segments Allocated to Trace All Possible Ray Paths!
- Not Enough Intersections Allocated to Finish Ray Trace!

This article explains why these errors should NOT be ignored, how they may be fixed, and outlines the difference between a segment and an intersection.

Authored By:

Published On:

Sample File:

Applies to:

OpticStudio

Article:

# What is an intersection? What is a segment?

Periodically, in complex systems with many objects, or in designs where rays strike a single object multiple times (think of an integrating sphere), the default values for the maximum number of intersections and/or segments is not sufficient. As a result, you might see one of the following error messages:or

Both of these error messages should be considered as “hard” errors. In other words, they should NOT be ignored; ray trace results can be wrong if the maximums are not increased to a sufficient level.

This article is aimed at not only explaining why these errors should not be ignored, but also to explain how to address the errors, and outline the difference between a segment and an intersection.

First, let’s define what each one of the terms mean. An intersection is a point at which a ray strikes the face of an object. A single ray may strike the same object many times, and each time the ray hits the face of the object, it is tallied towards the total number of intersections.

A segment is the portion of a ray path from one intersection to the next. When a ray is launched from the source, it travels to the first object. This is the first segment, or segment number 1. At the point of intersection on the face of the object, the ray may split into 2 more rays (one transmitted and one reflected, for example), and each of those rays are another segment (for a total of 3).

To make this distinction clear, observe the diagram below. A single ray is incident onto the front face of a plane parallel plate. In this scenario (ignoring ray splitting), there are a total of 3 ray segments, and 2 intersections (one at the front face, and one at the back face). Each segment is colored differently in the plot below.

How are rays colored by segments? In the settings of the NSC Shaded Mode or NSC 3D Layout, you may choose to “Color Rays By” Source #, Wave #, Configuration #, Wavelength or Segment #.

It is sometimes helpful to think of ray segments and intersections as a “family” of rays. After any point of intersection, a “parent” ray can be split into a number of “child” rays. Each one of these child rays can be the parent of another set of child rays, much like a family tree. Since the maximum intersections and segments are applied per ray launched, you can think of each ray launched from the source as having its own family tree. If a maximum is reached, Zemax OpticStudio will issue an error, indicating that not enough segments or intersections have been allotted.

As you can imagine, ray splitting quickly populates the number of segments Zemax OpticStudio needs to trace. If we revisit the example shown above, the total number of segments quickly increases. For example, if we consider the Fresnel reflected rays from both the front and back surface of the plate, then there are a total of five segments. If each child ray then hits another interface and splits into two of its own child rays, we have a total of 9 segments, and so on. Moreover, it’s possible that we may scatter into multiple rays at a given interface, and each of those scattered child rays hits another scattering surface, adding another generation of child rays!

# Maximum Number of Intersections and Segments Per Ray

So where do we change the parameters which control the number of intersections and segments which can be used in the ray trace? Along with a number of other parameters, these two user-defined values can be modified in the System explorer, under Non-Sequential:Every control within this dialog defines how rays are traced within an NSC group in Zemax OpticStudio. For details on any specific control, you may refer to the following section of OpticStudio help files: The Setup Tab > System Group > System Explorer > Non-Sequential.

The maximum number of segments and intersections are used to set the maximum number of allotted segments or intersections per ray launched. This means that each ray launched from a source can have up to the maximum number of segments and intersections defined. So, if the maximum number of segments is 1000, and 5000 individual rays are launched, Zemax OpticStudio can store up to 5 million ray segments.

So why does Zemax OpticStudio allow these parameters to be user-defineable? Why doesn’t Zemax OpticStudio just trace as many segments as is needed to complete the trace? The reason for this is that Zemax OpticStudio would have to reserve a lot of memory to potentially support a huge number of segments. In most cases, this isn’t necessary, and would slow down the ray trace.

The total RAM requirement is about 140 bytes multiplied by the maximum number of segments. Setting the limit at 100000 segments would require 14Mb of RAM per ray. For this reason, do not needlessly set the maximum to very large number! The limit that Zemax OpticStudio will allow is 2 million ray segments.

Note that with even a modest number of segments, Zemax OpticStudio can still trace millions of rays. The maximum number of segments is only a limit on how many segments are allows in one single ray. Most Zemax OpticStudio features only use one ray at a time, so the total RAM requirement is driven by the maximum number of segments rather than the number of rays traced.

# Why the Segment and Intersection Errors Should NOT be Ignored

Given what we now know about segments and intersections, there is one other important piece of information to fully understand why the segment and intersection error messages should not be ignored. This piece of information has to do with the order in which Zemax OpticStudio traces non-sequential rays.A ray will be trace until it reaches one of the limits/maximum controls specified under the Non-Sequential tab of the System Explorer. However, if not enough segments or intersections are allocated to trace all of the possible ray paths, Zemax OpticStudio will issue an error and terminate the trace (when Ignore Errors is turned off). To reiterate, these error messages should NOT be ignored.

Here’s why. Let’s break down a ray trace into a family tree, much like the analogy which was made earlier in this article. After each intersection, let’s assume the energy is equally divided into two rays, a "reflected" and a transmitted ray. To demonstrate the hierarchy, the “reflected” rays from each intersection are drawn in red, while the transmitted rays are drawn in black.

Each intersection is drawn as a blue bar (NOTE: Each bar represents 1 intersection in this model. The blue bars do NOT represent a volumetric plate with both front and back faces). Given this sequence of ray tracing, upon each intersection, the total number of segments is equal to 2^(n+1) – 1. So after the third intersection, we have a total of 15 segments, or 2^4 – 1 = 15.

Note the numbering scheme for the segments in the diagram above. Ray segment 1 is incident on the first interface, and splits into 2 rays: a transmitted and reflected ray. Zemax OpticStudio continues to trace the transmitted energy, until that ray reaches its minimum relative ray intensity, for example. So, Zemax OpticStudio continually tracks the transmitted portion of the energy (as in segments 2, 3, and 4), then returns back to the last point in which splitting occurred. The transmitted energy of that ray is then traced until its minimum is met, and so on.

As you can see from this numbering scheme, if not enough segments are initially defined, we may be neglecting rays which carry a significant portion of our initial energy. As in the example given, if a maximum of 8 segments were defined, Zemax OpticStudio could not even trace ray segment number 9, which has half of our initial energy! If this were the case, how could we trust the total energy calculation collected by our detector?

So why don’t we determine which segment to trace first by its intensity? Well, to do this, we would have to store a large list of data in memory, which would significantly slow down the ray trace. So, Zemax OpticStudio traces rays in a recursive loop, which is proven to significantly increase ray tracing speed!

The bottom line is, never ignore the segment and/or intersection errors that Zemax OpticStudio issues. Always make sure that there are enough segments and intersections allocated to trace all possible ray paths. However, don’t arbitrarily set the values to high. Instead, only increase these values as needed.

# Summary

Zemax OpticStudio allows a user defined number for the maximum number of segments and intersections allotted for ray tracing within a Non-Sequential group. If the number is not set high enough to trace all possible ray paths, then Zemax OpticStudio will issues error messages such as “Not Enough Segments Allocated to Trace All Possible Ray Paths!” or “Not Enough Intersections Allocated to Finish Ray Trace!”. These error messages should be treated as “hard” errors, and should not be ignored. This article has described what segments and intersections are, where to modify the default maximum intersection and segment values, and why it is important not to overlook these error messages.

# References

Zemax Optical Design Help files, Zemax LLC