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
Boogieman
Posts: 34
Joined: Wed Apr 18, 2018 9:03 am

Angular range of ray arrays

Post by Boogieman »

This is software pyracy
:lol:

Is there a way to create a point light source that only radiates in a defined angular range?
I want do to model a camera with a very small aperture, so it is almost like a pinhole camera.

My hacky solution idea would be to create a small 2d ray array and put a lense infront of it. But it would be nicer to be able to set the angles directly.
User avatar
christi
Posts: 203
Joined: Wed Oct 24, 2018 7:03 am
Location: Karlsruhe, Germany
Contact:

Re: Optics Workbench

Post by christi »

Try this script:

Code: Select all

import OpticsWorkbench
import math
from FreeCAD import Vector, Rotation

angle_start = -10
angle_end = 10
angle_inc = 1
dir=Vector(1,0,0)
rot=Rotation()
rot.Axis = Vector(0,0,1)

for a in range(angle_start, angle_end, angle_inc):
    rot.Angle = math.radians(a)
    ndir = rot.multVec(dir)
    OpticsWorkbench.makeRay(position = Vector(0, 0, 0), direction = ndir)
User avatar
Boogieman
Posts: 34
Joined: Wed Apr 18, 2018 9:03 am

Re: Optics Workbench

Post by Boogieman »

Thanks a lot.

I've tried the Optics toolbox a while now and it really helped me.

One thing i miss is an auto update function. Strangely sometimes it updates without clicking the button but i haven't figured out when this happens.
User avatar
Boogieman
Posts: 34
Joined: Wed Apr 18, 2018 9:03 am

transparent rays

Post by Boogieman »

Maybe its interesting

The rays can be prettified when you play with View -> Line Material -> Transparency and View -> Line Width. Although it is more an Opacity because 0 is transparent and 255 is fully opaque. I use realthunders Linkstage 3 branch latest release but don't know if this also works with the official release.


Image
https://github.com/realthunder/FreeCAD_ ... issues/786
User avatar
christi
Posts: 203
Joined: Wed Oct 24, 2018 7:03 am
Location: Karlsruhe, Germany
Contact:

Re: transparent rays

Post by christi »

Boogieman wrote: Sat Aug 21, 2021 2:30 pm Maybe its interesting

The rays can be prettified when you play with View -> Line Material -> Transparency and View -> Line Width. Although it is more an Opacity because 0 is transparent and 255 is fully opaque. I use realthunders Linkstage 3 branch latest release but don't know if this also works with the official release.
Looks nice. Thanks.
drmacro
Veteran
Posts: 8865
Joined: Sun Mar 02, 2014 4:35 pm

Re: Optics Workbench

Post by drmacro »

I'm missing something simple I think.

I ran the example1.py and it did work.

I made a sketch and a lens and a ray.

But, can't seem to get any refraction... :(
Snip macro screenshot-665527.png
Snip macro screenshot-665527.png (47.73 KiB) Viewed 3413 times
Just noticed I get no error when I change position of the lens in the file where I ran example.py

But, in the attached get:

Code: Select all

15:04:17  PropertyPythonObject::toString(): failed for <class 'OpticalObject.OpticalObjectViewProvider'>
15:04:17  Traceback (most recent call last):
  File "/usr/lib/python3.9/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.9/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.9/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.9/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
<class 'TypeError'>: Object of type FeaturePython is not JSON serializable
Attachments
FirstOptics.FCStd
(6.43 KiB) Downloaded 72 times
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
Boogieman
Posts: 34
Joined: Wed Apr 18, 2018 9:03 am

Re: Optics Workbench

Post by Boogieman »

That's strange. I loaded your file and it also doesnt work.
Then i create another lense. It doesnt work.
Then i create another ray. The new ray and new lens work.
Then i move the old ray. The old ray and the new lens work.

But i cant get the old lens to work and i cant see any clue why that is.
drmacro
Veteran
Posts: 8865
Joined: Sun Mar 02, 2014 4:35 pm

Re: Optics Workbench

Post by drmacro »

Boogieman wrote: Sun Aug 22, 2021 9:36 pm That's strange. I loaded your file and it also doesnt work.
Then i create another lense. It doesnt work.
Then i create another ray. The new ray and new lens work.
Then i move the old ray. The old ray and the new lens work.

But i cant get the old lens to work and i cant see any clue why that is.
good to know, I'll tinker more tomorrow...thanks.
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
Boogieman
Posts: 34
Joined: Wed Apr 18, 2018 9:03 am

Re: Optics Workbench

Post by Boogieman »

Kunda1 wrote: Tue Jul 13, 2021 5:20 pm Enhancements:
Ability to assign different colors to different rays
Ability to manipulate via the spreadsheet (integrating Spreadsheet WB)
Representing data points on graphs (integrating the Plot WB)
You can already select different colors for different rays: View -> Line Color

Also, i think you can already use the spreadsheet. Just create some variables there and use them as a parameter.

About the last one, i dont know what you had in mind there.
User avatar
Boogieman
Posts: 34
Joined: Wed Apr 18, 2018 9:03 am

Re: Optics Workbench

Post by Boogieman »

drmacro wrote: Sun Aug 22, 2021 10:24 pm good to know, I'll tinker more tomorrow...thanks.
I just saw that your ray has some differing properties in the View-Tab.
In "Line Material" and "Shape Material" there just is "<Material Object>" instead of all the sub parameter for these settings.
Are you using the latest version of the OpticsWB? Which FreeCAD version do you have?
If you cannot solve this right away by updating and reseting/restarting, its maybe better to open an issue at https://github.com/chbergmann/OpticsWorkbench/issues an continue the discussion there.
Post Reply