Solved

Source Two Angle DLL

  • 7 March 2022
  • 7 replies
  • 219 views

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!

icon

Best answer by David.Nguyen 8 March 2022, 11:37

View original

7 replies

Userlevel 6
Badge +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

Thank you David. 

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

Userlevel 6
Badge +2

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

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

 

Userlevel 5
Badge +3

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.

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);

 

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