Hi all, this is a long post but I think I need to describe my story to get the right kind of help - please bear with me!
I recently started to use FreeCAD to do some 3D modelling at work, and it's excellent - great job! At the same time, I realised how powerful FreeCAD could be for solving optical
layouts based on a series of constraints.
I'm a physicist working with optics, and when I want to draw an SVG diagram of an optical layout, I have to load up Inkscape and move lots of things around. If I want to move a mirror in an existing layout, I also have to move the light beams that I've drawn with respect to that mirror, and if I change an angle I also have to redraw the light that "reflects" off of other mirrors. Here's the sort of thing I draw:
My idea to solve this issue is as follows: I want to be able to programmatically define the relationship between mirrors and other optical components, and the links (light!) between them, and have a program draw the SVG diagram for me. For instance, a mirror at some angle will reflect its ingoing light at twice that angle, so a program can easily calculate this. I want to allow a user to define what optics there are, and how they link together (e.g. "mirror A is separated from mirror B by 50cm, and they are oriented at 45 degrees with respect to one another"), and have the program draw what it looks like in 2D.
...Initially I thought I could just have a user-defined angle associated with each optic, and a position, and an angle of incidence for a "start" node, like a laser. Then I thought it would be straightforward to just propagate the light beam from laser towards the first optic, calculating the angle it reflects, then propagating the light in turn to the next optic, and so on, recursively. This is actually what I did - I made a Python program
to do this, and got it quite polished. At that point, though, I realised that this approach does not work for layouts with cycles (i.e. when the relation between mirror inputs/outputs is described by a cyclic graph). This occurs if you try to reflect light from a mirror back towards that same mirror via some other mirrors. In this case, my program recursively lays out each optic until it gets to the link between the last optic and the first, and then it realises it can't rotate the first optic because it is already constrained by an earlier link. This results in light that doesn't reflect at the right angle:
How can the program solve this system's angles when the angle of one is dependent upon the angle of the others? With a constraint solver, like the one in FreeCAD!
After a lot of searching I found an academic paper
which describes an approach to solve angular cyclic graphs by breaking the graph of connected nodes down into "clusters", identifying what "type" they are, then reducing the total number of clusters by merging adjacent ones until there is only one big cluster. Its authors even made an example program in Python. I thought this was ideal, but the program is an absolute monster, with a lot of early Python libraries which are now outdated, and a lot of undocumented code.
I think FreeCAD can do what I want: it can solve systems of angular constraints. My question is: can anyone with more experience using/developing FreeCAD, having read the above description of what I'd like to do, give me some insight into how easy or difficult it would be to use FreeCAD to solve this sort of problem?
Thanks for reading!