Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple Beamsplitters #57

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

mgeismann
Copy link

I added simple beamsplitters:
The code was adjusted such that a ray can generate a "tree" of lines (instead of a "list") and then made optical elements of type 'splitter' reflect a beam (same as mirror) and add a new transmitted line (a new "ray branch") by setting the 'doLens' flag without changing the refractive index. I would revise the 'doLens' hack in the near future, but it works for now.

Naturally, only FreeCAD objects that consists of a single face/plane should be turned into splitters as otherwise an incoming transmitted ray will be reflected inside the object indefinitely (up to maximum iteration, generating a lot of extra rays).

There is no transparency, i.e., transmission and reflection coefficients as discussed in issue #31 (but I might tackle this in the future).

Note that my editor formatted the 'Ray.py' file (I use python-lsp with the ruff plugin, so the formatting is that of the Black formatter). If this is an issue let me know I will revert the formatting where possible.

Feedback is welcome.

mgeismann and others added 6 commits January 3, 2025 21:34
The structure of 'traceRay()' was adjusted to allow for tracing multiple rays
after an optical element to allow for semitransparent optics like beamsplitters.

There is no new functionality added and the tracing should behave as before.
Before implementing beamsplitters properly, use the pre-existing mirror element
to test the necessary code changes.

Instead of a single 'dNewRay', the code now uses a list of of those.

The changes already work turning a mirror object into a beamsplitter: if making
a plane a mirror, a ray is reflected and another is transmitted.

If the a cube is used instead of a plane, the transmitted rays will be reflected
and transmitted when exiting the cube. This might be desired for tracking
residual reflection but there is not reflection coefficient yet. Hence, when
trying to use, e.g., a thorlabs beamsplitter step file, the user should add a
face right where the actual coating is (the face where the two triangular halves
of the cube are glued together).

Turning the cube into a lens (piece of glass) with the mirror surface inside the
cube, however, does not work: the beam is only reflected but not transmitted
anymore. Look into this with low priority (in most of my models the angle of
incidence will be normal anyway).
All necessary classes were added (copied and adjusted from the mirror classes).
The new icon is based on the mirror icon and was modifed via Claude AI to
include a transmitted beam.

The splitter works as described in the last commit (only single faces/planes
should be used as splitters).

There are currently problems when trying to use the optics workbench in an
assembly4 assembly: added mirrors do not seem to work. At least when the linked
parts are assigned to be mirrors after insertion. I believe this worked in the
past, but maybe I added the mirrors in files prior to inserting them in the
assembly.
The missing 'splitter' entry caused problems when adding more than one splitter in
a document.
@chbergmann
Copy link
Owner

Thank you for the contribution. We can use it as a base for the semi-transparency feature, but I do not want to merge it in the way it is implemented now.
Instead of implementing a new optical object "beam splitter", i would add a new input parameter Transparency to all mirrors (default=0%), maybe also for absorbers, but not for lenses. I think it is not a good idea to use the Transparency parameter from the view object, because it is only for how the object is displayed on the screen. For rays, the transparency can only applied for the whole ray, but we need it for each line segment.
The ray splitting then must be applied to all optical objects with transparency, not only to those consisting a single face/plane, everything else is confusing and does not match the reality.
Furthermore we want to have an energy density parameter in the statistics data which is generated when a ray hits an absorber to see how much percent of the original ray reaches the absorber.

Re- formatting the code is okay as long it is done in a separate commit without any new code or logical changes. I am not sure, but it seems you did that.

@mgeismann
Copy link
Author

Thank you for the contribution. We can use it as a base for the semi-transparency feature, but I do not want to merge it in the way it is implemented now.

My pleasure and thanks for the feedback!
At the moment my branch is doing what I need but I am interested in continuing the work to get to something that we can merge.

I agree that a transparency parameter would be useful and that a new optical object is not strictly required.

Regarding single faces as optical beamsplitters/elements:
My use-case and ultimate goal is to use thorlabs step files and have the workbench trace the light propagating through a simple optical setup with mirrors, lenses and beamsplitters. The beamsplitters I would use are these): cubes made up of prisms glued together with a beamsplitter coating on one of the glued surfaces. Hence, in the Optics Workbench I would turn the cube into a lens in order to have refraction for non-normal incidence, and add a beamsplitter face between the two prisms (In my version of the branch, if the beamsplitter is inside a lens, it only reflects. I guess this is a "bug" that could be fixed.)
Similarly, the mirrors I would like to use, e.g., these, only have one reflective surface.

Hence, to me, single faces as optical objects makes sense.
This would allow to simulate the propagation of a transmitted ray through the volume of a semi-transparent mirror and there would be no need to deal with "infinitely" bouncing beams within a semi-transparent object as shown in this screenhost:
image
The cube is a beamsplitter displayed with wireframes. The transmitted part of the impinging ray (marked with red arrow) "bounces" inside the cube spawning another outward propagating ray on each internal reflection.

What do you think? (If you prefer, we can move the discussion to issue #31 )

Re- formatting the code is okay as long it is done in a separate commit without any new code or logical changes. I am not sure, but it seems you did that.

Good to know. Unfortunately, I did not... The first commit includes formatting and other changes. For future submissions I will be more careful.

@mgeismann
Copy link
Author

Addendum: To demonstrate the faces as optical objects idea: Same setup as in the screenshot of my last comment. Here, however, I made the cube a lens and added a face (marked in green) which I turned into a beamsplitter:
image

@chbergmann
Copy link
Owner

I added the semi-transparency feature to mirrors with a Transparency parameter in this branch:
https://github.com/chbergmann/OpticsWorkbench/tree/semi-transparency

It also calculates an energy value for each ray hit, but there are still some issues with theses values in the CSV export

@chbergmann
Copy link
Owner

To get semi transparency work together with lenses, you could add a transparency parameter to lenses with the default of 100%. If the value is smaller and we do not have total reflexion a ray hit from the outside, add an additional mirrored ray in the same way the mirror does

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants