Skip to main content
Question

How do I calculate a ray intercept point with a standard surface?


Ivair.Gontijo

I am trying to develop a UDS (User Defined Surface) DLL and have been reading the excellent articles in knowledge base about this. Taking as the starting point the “us_stand.c” code for the standard surface (available in the folder /Zemax/DLL/Surfaces), I understand that Zemax provides an intercept point to the tangent plane (x0, y0, z=0) and direction cosines (l0, m0, n0) for the ray at that point. Then the real ray trace is performed in case 5 and for complicated surfaces there is no analytical solution for the ray intercept point on the surface. Hence an iterative solution is needed.

What I am struggling to understand is: how do those equations in case 5 work? I thought that there would be no analytical solution to find the ray intercept point with the standard surface. However, the equations in case 5 seem to be quite simple, although I was not able to derive them.  

Therefore, my questions are:

  1. Is the algorithm in case 5 of “us_stand.c” implementing a closed-form analytical solution, as opposed to an iterative algorithm?
  2. How were those equations derived? For example, what is the meaning of ‘a’, ‘b’, ‘c’, ‘rad’, etc in case 5? Are they defined and explained somewhere?
  3. Do you think it is possible to use these equations to super-impose a radially symmetric structure on the standard surface and still obtain an analytical solution (if that is what we have in case 5)?

Basically, I have an equation that I want to add to the equation of the standard surface. My understanding is that even in the standard surface case we should apply iterative methods, but it seems that the Zemax solution is a lot more elegant than that. Any comment and help with this will be greatly appreciated!

Thanks!

4 replies

David.Nguyen
Luminary
Forum|alt.badge.img+2

@Ivair.Gontijo 

 

Its a good question. I’ve always wanted to write the equations down for people to easily have access to this information but never found the time to do it…

For me the closest description of this algorithm is found in the book Aberrations Of Optical Systems by W T Welford in Chapter 4 Finite Raytracing. Eventually, you’ll want to pay close attention to Section 4.7 Raytracing through quadrics of revolution.

Regarding question 1. Yes, for a standard surface with only a radius of curvature and a conic coefficient there is a closed form solution and it is what’s implemented in case 5.

Regarding question 2. There’s a relatively good match between the variable names in case 5 and the equations in the book. The transfer (finding the ray intercept with the surface) involves solving a quadratic equation. a, b, and c are the coefficients of the quadratic equation, and rad is basically the discriminant (they removed a factor of 4, but once you have the equations in front of you it’ll make sense). So what is this quadratic equation you need to solve?

In short (because I don’t have the time to go into the details now), its the equation of the sag (of the standard surface):

where r * r = x * x + y * y. And you can express the intercept coordinates (x, y, z) as a function of the vertex (you call it tangent plane) coordinates (x0, y0, z0=0) and the unknown (called Delta in the book) distance between those two points. This is visible in the code in the lines:

            (UD->x) = (UD->l) * t + (UD->x);             (UD->y) = (UD->m) * t + (UD->y);             (UD->z) = (UD->n) * t + (UD->z);

Where t is the unknown distance. At this point in the code, they’ve solved the quadratic equation already, but its just to show you how you’d derive the quadratic equation to be solved. You plug the:

x = l * t + x_0

y = m * t + y_0

z = n * t + z_0

Into the equation of the sag, and solve for t.

PS: in the book, they use an asphericity parameter epsilon, and as far as I remember it isn’t the conic coefficient but they give the equation to do the transformation (4.26). Double check this because I studied this a long time ago.

Regarding question 3. Its very unlikely, but it all depends on the equation of your sag (as you just saw). What kind of surface are you trying to model exactly? Did you not find something suitable among the existing surfaces?

I apologize for being brief on 2. but I really don’t have much time now. In the future, I’ll try to edit or make a clean version of this with details.

I hope it still helps though.

Take care,


David


Ivair.Gontijo
  • Author
  • Single Emitter
  • 3 replies
  • May 20, 2025

Thank you David for the detailed answer above and also for the reference to Welford’s book, which was very helpful! Yes, I noticed that in the book they use epsilon, which is connected to the eccentricity of the conic, which is in turn connected to the conic constant k by k=-e^2.

Unfortunately none of the surfaces in Zemax are sufficient to model the surface I need to work with. So, I am going to study that chapter in the book carefully, but you are right that with a more complex surface, an iterative solution will be needed.

Thanks again for taking the time to explain the details above!

Ivair


Ivair.Gontijo
  • Author
  • Single Emitter
  • 3 replies
  • May 20, 2025

By the way, equation (4.25) in Welford’s book is z = 0.5c(x^2+y^2+ez^2), which is in implicit form. It can be manipulated into the standard surface equation used in Zemax by making r2 = x^2+y^2 and rearranging it into 

cez^2 -2z + cr^2 = 0

 Then solve this quadratic equation, as r^2 is constant with respect to z. Choose the minus sign because when r = 0, z should also be zero.  Multiply above and below by the expression with the positive sign, to move the square root to the denominator. Then make e=1-k and you are done! :-)


Ivair.Gontijo
  • Author
  • Single Emitter
  • 3 replies
  • June 3, 2025

There is a mistake in my comments above, regarding the connection between epsilon and k. Epsilon is the constant used in Welford’s book implicit formula for the conic (I called it ‘e’ in my comment) and the conic constant ‘k’. The correct relation between these two quantities is epsilon = (1+k).

It was fun to derive all the formulas used in the standard surface dll code. Once ​@David.Nguyen pointed me in the right direction, to use the implicit equation for the conic, it was easy. Thank you David!

Note that there is also a third constant related to these two, which is the eccentricity. However, we don’t use it, so there is no need to complicate things further. :-)  


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