Optics Workbench

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Post Reply
User avatar
christi
Posts: 203
Joined: Wed Oct 24, 2018 7:03 am
Location: Karlsruhe, Germany
Contact:

Optics Workbench

Post by christi »

Hallo FreeCAD fans,

I have created an new workbench for geometrical optics simulation
Image

Until it is unfinished and not installable from the Addons menu, you can download it here:
https://github.com/chbergmann/OpticsWorkbench
Last edited by christi on Tue Jul 13, 2021 5:12 pm, edited 1 time in total.
User avatar
christi
Posts: 203
Joined: Wed Oct 24, 2018 7:03 am
Location: Karlsruhe, Germany
Contact:

Re: Optics Workbench

Post by christi »

johnwang wrote: Sun Jul 04, 2021 1:03 am Has anyone play with this KDP-2 from http://ecalculations.com/ An old Fortran design program

And there is a Koko which is based on KDP-2, its longer-term plan is to integrate with FreeCAD
https://github.com/dinosauria123/Koko
There are lots of tools for geometrical optics simulation in the internet. But they all use there own libraries and GUI elements. Porting this to FreeCAD is not easy.
The main part of my Optics workbench is not the optical physics, which is quite easy. The main part of the work is to get it work with FreeCAD objects.
I make use of the openCascade library that is integrated in FreeCAD. Most of the needed vector arithmetics functions are already included there.
Last edited by christi on Sun Jul 04, 2021 9:25 am, edited 1 time in total.
User avatar
christi
Posts: 203
Joined: Wed Oct 24, 2018 7:03 am
Location: Karlsruhe, Germany
Contact:

Re: Optics Workbench

Post by christi »

spanner888 wrote: Sat Jul 03, 2021 10:38 pm
christi wrote: Sat Jul 03, 2021 7:39 pm Work is still in progess, but you can already draw some sketches and use it as optical mirrors
Looks especially nice for simpler use cases than many optics tools I have looked at...and not used.

However in my own dumb user klutz fashion, I have not quite understood how to define the elements. It would be very usefull if you could share the FreeCAD model of your example, so I can get past whatever sillyness I have done to cause below (just two sketches, each with one line, and one sketch made into a mirror, then adding a Ray gives below)

Code: Select all

08:06:28  Illegal storage access...
08:06:28  Traceback (most recent call last):
  File "C:\Users\spanner888\AppData\Roaming\FreeCAD\Mod\OpticsWorkbench\Ray.py", line 40, in execute
    self.redrawRay(fp)
  File "C:\Users\spanner888\AppData\Roaming\FreeCAD\Mod\OpticsWorkbench\Ray.py", line 64, in redrawRay
    self.traceRay(fp, pos, linearray)
  File "C:\Users\spanner888\AppData\Roaming\FreeCAD\Mod\OpticsWorkbench\Ray.py", line 95, in traceRay
    isec = line.Curve.intersectCC(edge.Curve)
<class 'RuntimeError'>: Illegal storage access! Please save your work under a new file name and restart the application!
If I select the second sketch, then the mirror and try to create a ray, then get the same error again.

Then I tried making another sketch with a rectangle and made that an absorber, but still get above error trying to add a Ray, so your example file would help me work out how to correctly use your addon.
I have pushed some Bugfixes. Please update the workbench and try again.
There is also an example available. Menu Optics -> Example 1
spanner888
Posts: 326
Joined: Tue May 28, 2019 10:51 am

Re: Optics Workbench

Post by spanner888 »

Thanks for the quick reply & the updates.

That is a very interesting way to create an example, I like it, and it works well.

I am still having some issues when I create a ray in the GUI, but noting your very new release comments, I will be patient, especially as I just released some code to the forum today as well!

Mean while, I will tweak your example code for the situation I want to test.

Thanks for a very interesting workbench.
spanner888
Posts: 326
Joined: Tue May 28, 2019 10:51 am

Re: Optics Workbench

Post by spanner888 »

spanner888 wrote: Sun Jul 04, 2021 10:36 am Mean while, I will tweak your example code for the situation I want to test.
I begin to see scripting is a very good way to use your workbench. At the moment just placing Rays for several light sources (soon at different heights and angles) and showing the beam spread and mirrored reflections into a lens.

So scripting allows easy copy/paste/edit and looping to create all the rays at different angles and positions.
User avatar
Vincent B
Veteran
Posts: 4713
Joined: Sun Apr 05, 2015 9:02 am
Location: La Rochelle, France

Re: Optics Workbench

Post by Vincent B »

Here two gems to test the future 3D feature. ;)
Attachments
RoundBrilliantCopy.FCStd
(16.93 KiB) Downloaded 217 times
TrillantHeartCopy.FCStd
(20.83 KiB) Downloaded 185 times
user1234
Veteran
Posts: 3328
Joined: Mon Jul 11, 2016 5:08 pm

Re: Optics Workbench

Post by user1234 »

Nice work!

Greetings
user1234
User avatar
christi
Posts: 203
Joined: Wed Oct 24, 2018 7:03 am
Location: Karlsruhe, Germany
Contact:

Re: Optics Workbench

Post by christi »

GlouGlou wrote: Mon Jul 05, 2021 9:23 am Here two gems to test the future 3D feature. ;)
Thanks. This will be interesting if lenses will work some day...
User avatar
christi
Posts: 203
Joined: Wed Oct 24, 2018 7:03 am
Location: Karlsruhe, Germany
Contact:

Re: Optics Workbench

Post by christi »

3D support has been added, but it is not very accurate.
I have the problem that I cannot determine the exact position of a normal on a 3D surface.
There is an API function Surface.normalAt(u,v). I have a Point on the surface in form of a Vector(x,y,z)
Does anybody know how to get the parameters u and v from the vector ?
User avatar
christi
Posts: 203
Joined: Wed Oct 24, 2018 7:03 am
Location: Karlsruhe, Germany
Contact:

Re: Optics Workbench

Post by christi »

Fixed it. Mirroring in 3D space works now.
Image
Post Reply