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

Add ConcaveDiffractionGrating object and rotation with +/- keys #202

Merged
merged 2 commits into from
Feb 7, 2025

Conversation

birdylife
Copy link
Contributor

Hello everyone,
Please be gentle, this can be considered my first contribution to any OpenSource project, and I'm not a (good, in any case) programmer, too.
I'm working on a project that makes use of a monochromator which is based around a so called "holographic aberration-corrected grating". These are concave gratings em"blazed" on mirrors, which usually are, due to easier manufacturing, indeed circular and not parabolic. This refocuses the diffractions of the "selected" wavelength to the exit slit. (Aaand creates aberrations which are countered by specifically modifying the grating, but that's a different story)
I was therefore on the lookout for a good 2D raytracing software/framework and stumbled upon ray-optics more or less by accident - it was not the first thing I found, and I was already getting frustrated. The more happy I was to have finally found such a promising base for simulating my setup.

To get to the point:
I created a new sceneObj called "ConcaveDiffractionGrating" (CDG) to the codebase. I modified some other lines of code in the necessary files to get it to work, although things like description and .svg files should be considered not implemented.
I created the CDG by mostly copying the source code of "ArcMirror" and then adding the bits of the planar "DiffractionGrating" to make it behave as I wanted. It can therefore be seen like a merge of these two sceneObjs.
I struggled (far too long) with getting the mirroring and diffracting the way it's supposed to be - it's functional, though, as is.
It is a bit hacky in some parts. (See line 372 and 390 of ConcaveDiffractionGrating.js, where a recalculation of the diffraction angle is done, because somehow the intensity calculation requires the angle to be calculated differently than before to work properly)

Additionally, since these kinds of monochromators do their wavelength-selection by rotating the grating around its middle point, I added some key-press functionality to "app.js" - namely for the +/- keys. They call the function "rotate" of the selected sceneObj. I've implemented this function for my CDG-object, but none of the other objects. See the code for "ConcaveDiffractionGrating"
--> This causes crashes of the app because the function "rotate" is not defined for all objects yet. I consider it a useful function though which should maybe be implemented for all objects. I believe someone more experienced with JS and it's classes / hierarchy etc. should implement this.

Have a look. If this is something that will eventually be accepted by the community, I'm happy to do the necessary changes or updates to the code myself to make it fully functional. (Description, svg files, tests etc) I might need some help with that, on the other hand.
I hope this is according to the contributions guidelines :)
Cheers, birdy

export

Copy link

vercel bot commented Feb 5, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ray-optics-fslk ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 5, 2025 3:21pm

@ricktu288 ricktu288 self-assigned this Feb 6, 2025
@ricktu288 ricktu288 merged commit 508ea6d into ricktu288:master Feb 7, 2025
3 checks passed
@ricktu288
Copy link
Owner

Thank you for your contribution! I made the following changes:

  1. Rename to 'Concave Grating' in the UI to avoid making the menu too wide (but keep the internal name for logical consistency), and move to the end of the mirror list since it is not a standard mirror.
  2. I remove your German description since a description for the users should not contain internal name of scene objects. I added a new description for English.
  3. You created the scene directory and added an example. Is that intended for the Gallery? If so, you should have a title and description and add it according to https://github.com/ricktu288/ray-optics/blob/master/CONTRIBUTING.md#contributing-items-to-the-gallery
  4. I added the preview image. However, I remove the item in the home page, since it is a bit redundant for the introduction page.
  5. I added the rotate virtual method to BaseSceneObj to prevent error when trying to rotate an object not supporting rotation.

Now for the rotate function, I think one should make it a bit more general, such as having the rotation angle and rotation center as the parameters, not just the direction. If the rotation center is not specified, then the default can be whatever the most convenient (such as p3 in your case). I think the rotate function can be later used in other features rather than just the +/- key. Also, currently it seems that the +/- key only work on the numpad.

One of the related feature is the Handle tool (see the help popup in the lower right corner). Currently, it is bind to control points individually, which make it hard to use and not always actually doing the transformation. For example, when you scale an ideal lens, the focal length should also be scaled, but it is not when using the handle bound control point-wise. If the rotate functions and also the similar scale functions are implemented, one can extend the handle feature to be able to bind object-wise, solving the issues and make it much more intuitive to use.

However, the case for GRIN glasses may be tricky, since the refractive index functions are designed to use absolute coordinates (see #69 (comment)), I don't know what is the expected behavior for rotate and scale for such objects, and possibly more discussion is needed.

If you have time and are interested in contributing more to this project, I would suggest trying to implement the rotate and possibly the scale functions to all scene objects.

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.

2 participants