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 ([-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