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?

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

- Calculate Eq. 5 with your two angles
- Take random samples from the two intervals described before Eq. 6 (f-eta_a, eta_a] and -eta_b, eta_b])
- Keep only those that fullfil either Eq. 6 or Eq. 7 (check the paper for more details)
- 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.

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(Hx * Hx + Hy * Hy));`

`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.