Closed Mateasek closed 4 years ago
Interesting. Yes you are right the build order was never intended to cope with hugely thick lenses.
I think we may need to intersect the front and back spheres with a cylinder to cut off the spherical caps. Then union these with the barrel. I'd be very worried about numerical accuracy issues though. This will take some thought.
The issue with convex surfaces could be solved by intersecting surface spheres with a cylinder, which is extending beyond the lens body. This could work and is as simple as what is used now. The convex surfaces would keep the same intersection with the barrel as they have now and would be subtraced. It would keep the number of the operations same and could be accurate.
I probably should stop posting comments late in the evening... You are right that this needs a thought, the poposed pocedure was also not handling thick lens correctly also.
After some time I think introducing an upper threshold to center thickness could be a good option. It could either stop the lens init completely and we could add extra classes for thick spherical lenses or it could be used to switch to construction suitable for thick lens. This way the current simple and efficient construction would be kept and probably used in most of the applications while keeping the thick lens option.
I've implemented different construction for thin and thick lens cases into Planoconvex (1,2 from top), BiConvex (3, 4 from top) and Meniscus (5, 6 top) lenses. It still has to be checked, but looks promissing. The threshold for the thin (current construction) to be used is the maximum venter thickness it stilll works for. I have to tests still, but looks promissing by eye-metrics.
If you have a PR, I'll take a look.
Just curious, is it ever practical to have such thick lenses? I would have thought such thick lenses have very little physical relevance even if it is a legitimate bug.
I would be worried about the fact that biconvex, planoconvex and menisucs lenses can behave in very unpredictive way.
I made a draft PR #355 to show what I've done so far. The only lens not finished is the meniscus, which has some problems close to the edges of the back surface. I will change the structure of the unittest class to introduce more versatility to the methods for surface testing, which might solve the issue.
The problem is that even though the ray is shot towards the edge of the lense, it misses. I have to investigate if it is an error in the construction or problem of the ray or just numerics.
I think I am done from my part. The new way of lens construction and tests are in PR #355.
While putting together tests for lens primitives I discovered another issue. The construction for large center_thickness parameter can produce lenses of wrong shape or even no shape at all, see in the picture. The left column are menisus lenses, the right contains biconvex lenses. The centre_thicknes parameter is increasing from top to bottom. The increase causes the meniscus lense to have wrong position and shape of a biconvex lens. The biconvex lens has wrong position and decreasing diameter up to a point when it "dissapears".
The lenses were generated using this code:
This is in my opinion caused by way lens objects are constructed with CSG. In both cases (BoConvex, Meniscus) the procedure is first intersection of the front and back spheres and then intersection of the result with the barrel. This fails when the distance of the sphere centers gets too large due to the center_thickness parameter.
I know these examples are not probably relevant for any realistic lenses, but I think this behaviour should not be allowed. I see two solutions:
I can combine a fix for this issue into a PR with tests I've been working on. I would personaly prefer the second option.