cflin wrote:
I second that. Some examples would be really helpful.
looo wrote:
Do you have a simple example or a short guide how to start?
One of the easiest examples to set up an optical system is:
Code: Select all
from pyrateoptics import build_rotationally_symmetric_optical_system
from pyrateoptics import draw
from pyrateoptics import raytrace
components = [(100, 0, 20, 1.5, "lens1front", {"is_stop": True}),
(-100, 0, 5, None, "lens1back", {}),
(0, 0, 100, None, "image", {})]
# (radius, cc, thickness, material, name, options)
(s, seq) = build_rotationally_symmetric_optical_system(components, name="my_opticalsystem")
r = raytrace(s, seq, 11, {"radius": 9.0})
draw(s, r) # show system + rays
It is stolen from the README.md and provides a lens with a refractive index of 1.5 with front and backside curvature radius of 100 mm. (As you can see in the components definition.) Further it generates the optical system, performs a raytrace of 11 rays in an xy fan and draws system together with the rays. The drawing function needs Matplotlib which is a good compromise if you don't want to use a GUI like FreeCAD.
In s there are several variables which provide access to the lens data. For e.g. modifying the tilt of on surface in comparison to another, just use:
Code: Select all
s.elements["stdelem"].surfaces["lens1front"].rootcoordinatesystem.tiltx.setvalue(0.1) # tilt first surface
s.rootcoordinatesystem.update() # update all coordinate systems
r = raytrace(s, seq, 21, {"radius": 9.0}) # trace again
draw(s, r) # show system + rays
I am not sure whether this code can be executed from the FreeCAD console, but on a plain python2.7 and python3.x console it should work.
Hope this helps for a first insight.
Best wishes
Johannes
(PS: Notice that the raytracing works, but some details are not tested and ready for production use, therefore do not rely too much on the results.)