PyRayT icon indicating copy to clipboard operation
PyRayT copied to clipboard

Light rays skip the surface of the lens

Open meidihku opened this issue 2 years ago • 3 comments

Dear All,

I found that the rays skip one surface of the bi-convex lens and directly reach the imager, given a specific cone-angle (e.g. 0.1, 0.01) for the light source in the type "ConeOfRays".

The codes reflecting the bug are enclosed in the attached file. You can trace the ray propagation process to find out what I said.

Does somebody know why it happens and how to get it fixed?

Many thanks in advance.

Bug example.txt

meidihku avatar Mar 17 '22 16:03 meidihku

Hi Meidihku,

Thanks for pointing out this bug! I was able to replicate it on my own set-up and will try and get to the root of it in the next couple of weeks.

If you're able to find the bug before that, feel free to submit a pull request and I'll look it over.

-Ryan

rfrazier716 avatar Mar 17 '22 18:03 rfrazier716

Dear rfrazier716,

Though I did not completely solve the problem, I have got this problem mitigated by the simple modification toward your codes.

In the function "binomial_root(a, b, c, disc=None)" of the file "operations.py", I made the following modifactions:

'''original code ''' polyroots = np.where(linear_cases, np.tile(-c / (b + (b == 0)), (2, 1)), polyroots) '''modified code by Mei Di''' polyroots = np.where(linear_cases, np.tile(-c / (b + np.isclose(b, 0, atol=1e-06)), (2, 1)), polyroots)

correct for cases that have neither a or b terms

if there's not a or b and the discriminant is positive, return +/-inf, otherwise just + inf

this is for cylinder intersections cases

'''original code '''

c_terms_only = np.logical_and(linear_cases, np.isclose(b, 0)) ###numpy.isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)

'''modified code by Mei Di''' c_terms_only = np.logical_and(linear_cases, np.isclose(b, 0, atol=1e-05)) ###numpy.isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)

Then the situation is much better when you set a larger threshold for the judgement whether b is equal to 0.

Even so, a radical solution is still needed. Please try to work on this at your convinience.

Yours,

Mei Di operations_modified_python_.txt ray_sphere_relationship ray_sphere_intersection_algorithm

meidihku avatar Mar 23 '22 13:03 meidihku

Dear rfrazier716,,

Please check the attached file to see the further modification. It seems that the problem is solved, but I do not know whether the result is correct.

Have a nice day.

Yours,

Mei Di modification operations_modified.txt

meidihku avatar Mar 23 '22 16:03 meidihku