Skip to main content
Solved

Source Two Angle DLL


Hi there, 

I am trying to write a source DLL file to use in OpticStudio, which is based on the built-in source “Source Two Angle”. It would be great if I could use this as a starting point. Is the (cpp) code available for this source? Or is there something similar I could start with? 

Thank you!

Best answer by David.Nguyen

Hi Dries,

 

As far as I’m aware the source code for Source Objects isn’t readily available to the users. You can always try to ask Zemax themsleves if they’d be willing to share this code. Note that sometimes you can find user-defined objects in the Code Exchange, that can be helpful.

Potentially, what you want is a light modification of the Cone.cpp object. You want to sample rays from a cone described by the two user-defined angles. Have a look at this paper. I did something similar some time ago. The key was that to get uniform sampling you shouldn’t sample the cone angle uniformly. Instead, you sample a random variable (called eta, greek letter, in the paper) uniformly, and deduce the angle from it, if that makes sense. Someone else needs to correct me cause I’ve written this quickly but this is what you need to do (again based on the paper):

  1. Calculate Eq. 5 with your two angles
  2. Take random samples from the two intervals described before Eq. 6 ([-eta_a, eta_a] and [-eta_b, eta_b])
  3. Keep only those that fullfil either Eq. 6 or Eq. 7 (check the paper for more details)
  4. Then, and this is not in the paper, to get the angle behind the random sample you revert Eq. 5, that is your random angle is 2 * asin( eta )

I hope this can get you started, bear in mind there could be mistakes in my reply but the general idea should be correct. If you need Sobol sampling, this might be a bit more complicated and I would need to remind myself how its done to help you.

Take care,

 

David

View original
Did this topic help you find an answer to your question?

7 replies

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

Hi Dries,

 

The User-Defined Sources available can be found in your {Document}/Zemax/DLL/Sources folder. I think that with the installation you get:

  • Cone.cpp
  • fiber1.c
  • Lambertian_Overfill.cpp

You could start with Cone.cpp its a basic one.

I hope this helps.

Take care,

 

David


  • Author
  • 4 replies
  • March 8, 2022

Thank you David. 

So this means the source code of “Source Two Angle” is not available, correct? 


David.Nguyen
Luminary
Forum|alt.badge.img+2
  • Luminary
  • 1085 replies
  • Answer
  • March 8, 2022

Hi Dries,

 

As far as I’m aware the source code for Source Objects isn’t readily available to the users. You can always try to ask Zemax themsleves if they’d be willing to share this code. Note that sometimes you can find user-defined objects in the Code Exchange, that can be helpful.

Potentially, what you want is a light modification of the Cone.cpp object. You want to sample rays from a cone described by the two user-defined angles. Have a look at this paper. I did something similar some time ago. The key was that to get uniform sampling you shouldn’t sample the cone angle uniformly. Instead, you sample a random variable (called eta, greek letter, in the paper) uniformly, and deduce the angle from it, if that makes sense. Someone else needs to correct me cause I’ve written this quickly but this is what you need to do (again based on the paper):

  1. Calculate Eq. 5 with your two angles
  2. Take random samples from the two intervals described before Eq. 6 ([-eta_a, eta_a] and [-eta_b, eta_b])
  3. Keep only those that fullfil either Eq. 6 or Eq. 7 (check the paper for more details)
  4. Then, and this is not in the paper, to get the angle behind the random sample you revert Eq. 5, that is your random angle is 2 * asin( eta )

I hope this can get you started, bear in mind there could be mistakes in my reply but the general idea should be correct. If you need Sobol sampling, this might be a bit more complicated and I would need to remind myself how its done to help you.

Take care,

 

David


  • Author
  • 4 replies
  • March 8, 2022

Thank you very much David for setting me on my way! This is very helpful. 

 


David
Luminary
Forum|alt.badge.img+4
  • Luminary
  • 336 replies
  • March 13, 2022

Hi Dries,

I don’t know that it would be of use to you, but some tine ago I posted source DLLs for fan and ring sources. They can be found here.


  • Author
  • 4 replies
  • March 21, 2022

Hi all, 

I started working on my version of Source Two Angle as a DLL, and so far the progress has been OK. However, I find myself struggling with finding the correct direction cosines when Angular Shape = 0 (rectangle) and Uniform Angle = 1. The half angles are implemented correctly, but almost all the rays pass through the center. I don’t see how I can get a uniform distribution. Below is a part of my code, if somebody can take a quick look at it, that would be awesome! Thanks in advance!  

 

double Hx, Hy;  // X and Y Half Width (0~89 * PI / 180)

double maxTh = atan(sqrt(HxHx + HyHy));

double maxPh = atan(Hy / Hx);

double phi = PI * (dist(gen) - 0.5);

double maxR;

if (abs(phi) <= maxPh)

     maxR = Hx / cos(abs(phi))

else

     maxR = Hy / sin(abs(phi));

double R = 2 * maxR * (dist(gen) - 0.5);

double theta = asin(R);

l = sin(theta) * cos(phi); m = sin(theta) * sin(phi); n = cos(theta);

 


  • Author
  • 4 replies
  • March 28, 2022

Dear all, 

An update on my progress; I changed my approach of the uniform angle issue mentioned above, instead of trying to fit all rays into a square, I now sample the rays in a uniform way, comparable to what happens in cone.cpp, in the circle that fits over the square. I then perform a check to see if the generated ray is passing through the square. If not, I generate a new ray until it fits. Although there is some computation time lost, it does give me a very good output, comparable with Source Two Angle. 

 


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