News for hackers. Stuff that matters.
Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by pwnna on Sunday March 22, 2015 @07:32PM (#9248701)
So I've looked at potentially working with OpenSCAD before, but unfortunately had to go back to something like Autodesk Inventor before really starting. The biggest problem I have with all open source 3D CAD systems are the lack of parametric modeling.

If you're unfamiliar with this, this basically is setting constraints on your geometry. For example, you can say that edge A has the same length as edge B, and it mirrors across plane C, which is 10 cm away from the primary XY plane.

This is essential to my workflow in 3D modeling and makes most geometry based operations (such as specifying that edge A is 10cm and starts at 3,4) obsolete. It also allows easy assemblies: you can specify the axis of shaft A need to be coincidental with the axis of hole B.

Plain text based 3D modelling would be awesome as you can use reasonable revision controls and have reasonable merge strategies.. but the lack of parametric modelling, at least for me, is a deal breaker. I've looked into writing a library for parametric modelling in Python, but then I realized that you probably need to be a PhD in geometry to write a correct implementation with reasonable speed....

Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by colah3 on Sunday March 22, 2015 @11:05PM (#9249305)
Author of ImplicitCAD here. I completely agree.

At first, I tried to implement constraints in a Haskell DSL. Unfortunately, constraints usually only partially describe your object. Even a well-constrained object can be flipped and maintain the constraints, in most systems. I coudln't find a reasonable way to implement a text-based interface for this. It really needs to be graphical.

I abandoned ImplicitCAD to write a constraint-based CAD program with my friend Rob Gilson. (I handled constraint solving with gradient descent, which worked surprisingly well, and a dab of grobner bases here and there.) We got some neat stuff working, but eventually got pulled away to other projects.

I think there's a lot of interesting work to be done linking programmatic and graphical CAD. In particular, I think there's neat connections between constraint based CAD which is a form of visual logic programming, and functional programming. (Aside: I like Bret Victor's talk "Stop Drawing Dead Fish" which is on a kind of related topic.)

Unfortunately, I'm too busy with ML research these days to work on this stuff!

Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by auxym on Monday March 23, 2015 @08:44AM (#9250546)
As a frequent user of Solidworks for ~4 years, I'd have to guess that CAD constraint solvers are not an easy problem.

It happens pretty often that you'll modify a single constraint (flipping it is a common culprit), the solver will get "confused" and flip a bunch of your other constraints around. Constraint conflict resolution also often gets very hairy to almost impossible. Sometimes the fastest thing to do is to nuke a good part of your constraints and start over -- in a saner way.

I guess the BIG CAD packages (CATIA, NX) might be a bit better at this, or at least better at strongly encouraging saner ways of build parametric constraints (which is what I've heard).

It's too bad that there isn't a simple, intuitive and useful free/oss CAD software out there. With the whole hobbyist maker movement explosion out there, a lot of people would be thrilled to have something like that. Though, it seems that things are not very much better in the PCB CAD/CAM world either.

Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by colah3 on Monday March 23, 2015 @10:40AM (#9251157)
I was really excited about handling some of the messy constraint situations better than existing tools. I'll split this into two pieces:

> It happens pretty often that you'll modify a single constraint (flipping it is a common culprit), the solver will get "confused" and flip a bunch of your other constraints around.

For "confused" constraint solvers, I see this as largely being a problem of there being lots of solutions to a well constrained system, because of flips and such. It needs to be easy for the user to specify which one they want.

Our approach was to have fast pulls of the mouse temporarily over ride the constraint solver. So, if you needed to flip the model, you do a really fast pull and it would flip. This works much better with multi touch, where you can just grab a few points with different fingers and force your model into whatever shape you want.

> Constraint conflict resolution also often gets very hairy to almost impossible.

There's some really powerful tools from algebraic geometry I tried to apply to this. In particular, there's these things called Grobner Bases which you can use to test if certain polynomials imply that another is true, false, or if it's independent of them.

From the users perspective, I wanted to use these to do a few things.

(1) Display implied constraints. If you make three corners of a quadrilateral perpendicular, the fourth is forced to be perpendicular. I grayed out perpendicular constraint could alert you to this, and prevent you from adding a conflicting constraint. Obviously, that example is kind of silly, but I think that propagating constraints through the whole model would really help people understand how more complicated models are constrained.

(2) If you try to add a constraint which conflicts with preexisting ones, highlight in red a minimal set it conflicts with.

I never got this part of the project to work though. I did some very small proof of concepts in sage, but couldn't really get things to work. I'm not really sure how realistic it is to make these work for real models.

Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by amk_ on Monday March 23, 2015 @01:04PM (#9251947)
It's not FOSS, but the new WebGL-based Onshape[1] from the original Solidworks team looks like it is going to be making waves. It's free for small public projects (Github-style). They are licensing the existing Parasolid and D-Cubed libraries to do constraint-solving[2], which hints at the a) separation of concerns from the CAD UI and back-end layers, and b) complexity of the CAD kernel problem.

[1]: https://www.onshape.com [2]: http://plmsource.industrysoftware.automation.siemens.com/plm...

Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by pwnna on Monday March 23, 2015 @03:03PM (#9252745)
> I think there's a lot of interesting work to be done linking programmatic and graphical CAD.

I thought about this as well, but I don't know anyone who works with CAD who would likely switch their work flow from GUI to text-based, other than people in this thread, I suppose.

Furthermore, while I don't know about the details on how to implement a text-based 3D modelling language for constraint based modelling, I don't think there's a lot of point if a GUI is going to be attached to it anyway. Existing systems already do a reasonable job.

One of the most annoying part of the confused constraint system, for me, is that it is difficult to fix the constraints. Options are likely to be hidden behind layers and layers of menus and dialog. A text file can be easily searched and diffed, which in my mind should make a confused system easier to resolve. So maybe this kind of constraint based CAD should have both a language and a revision control system built into it, or something.

Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by colah3 on Tuesday March 24, 2015 @11:44AM (#9257303)
> but I don't know anyone who works with CAD who would likely switch their work flow from GUI to text-based, other than people in this thread, I suppose.

Programming doesn't have to be writing text. :P

Everyone seems to be thinking about APIs to the CAD program, which solidworks, autodesk, and presumably others provide.

I had in mind a pretty deep way to embed a lambda calculus into the visual interface. The hope was to make it intuitive to create powerful parametric models, where every sketch is a function of different parameters. We never implemented that part, though. :/

Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by toong on Monday March 23, 2015 @05:09AM (#9250005)
I think CAD constraints would always be expressed in a linear system. I'm wondering if one could use Cassowary for constraint solving here ?

Somehow UI-control-layouting with constraints feels similar to constraints in CAD drawings ? :-)

+ How does gradient descent work with over-constrainted models ? (as in: impossible to satisfy all constraints). You need some way to back out of those or relax one of the constraints.

Ref: http://en.wikipedia.org/wiki/Cassowary_(software)

Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by colah3 on Monday March 23, 2015 @10:23AM (#9251037)
> I think CAD constraints would always be expressed in a linear system

Typically, you want to at least be able to express the lengths of lines, and the values of angles. I don't know how you could do this without using at least quadratic terms. So you have to do at least quadratic programming, and there's some things that can add higher degree terms.

Moreover, extremely similar problems are studied in automated geometric theorem proving, and they also get pulled into using polynomials.

Unfortunately, these problems are much much harder than linear programming.

There's some really powerful tools from algebraic geometry, mainly Grobner Bases, which you would ideally want to use. They're ridiculously powerful. Not only can you use them to solve systems of polynomial equations, but you can also test whether a set of equations implies another polynomial, or conflicts with another polynomial -- super useful for dealing with over-constrained models.

Tragically, the relevant algorithm is O(exp(exp(n))) -- well, or at least, that's the best upper bound anyone can probe, in practice it isn't that bad. Still, I quickly ran into computational problems. Grobner bases, also, while great are tricky to work with if you only want real valued solutions. They like to give you complex valued solutions to problems, and complex valued solutions to your CAD constraints are usually not what you are looking for.

> How does gradient descent work with over-constrainted models ? (as in: impossible to satisfy all constraints). You need some way to back out of those or relax one of the constraints.

In my implementation, each constraint was a separate cost function, which I added together. Normally, when you run the solver, it pushes all the constraint costs to zero, and you know you've solved everything.

Sometimes it would get stuck in a local minimum and require user intervention to help it get to the right solution. That was surprisingly rare.

If you have conflicting constraints it simply fails to reach a cost of zero at all. You can handle that in your interface however you like. The obvious thing is to try and solve a constraint immediately after adding it and then reject the constraint if you can't.

(I really didn't expect a local optimization method like gradient descent to work so well, but it did. That said, if I attacked the problem again I would try to use some sort of second order optimization method, I think.)

Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by toong on Tuesday March 24, 2015 @06:33AM (#9255741)
Thank you for your elaborate reply.

My my view is probably way too simplistic, but I'm really wondering how you would end up with quadratic terms if you need to define stuff like:

* this line needs to be 1/3 the length of that line

* these set of lines should start 50mm left of this line

I can see how trigonometric expressions could be useful to specify angles (although a constant there covers 99% of the user-cases?).

Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by colah3 on Tuesday March 24, 2015 @11:41AM (#9257278)
> * this line needs to be 1/3 the length of that line > * these set of lines should start 50mm left of this line

Remember that you're working with points. So, to express the length of a line, you need something like (x1-x2)^2 + (y1-y2)^2 .

If you just wanted to do things like "this point is +(0,10) of this other one", you're doing a really simple constructive system, which is easy to evaluate, but not anywhere near as flexible or powerful. ImplicitCAD/OpenSCAD trivially do that, just without a nice interface.

Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by ObviousScience on Monday March 23, 2015 @02:12AM (#9249685)
I've had an interest in constraint-based CAD programs (with an interest in designing things for 3D printers), and was wondering if you could recommend any literature on the subject.
Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by colah3 on Monday March 23, 2015 @10:45AM (#9251189)
Sadly, I never did a serious literature review.

That said, I naively tried a bunch of naive approaches and had quite a bit of success with plain old gradient descent -- it was really surprising. I'm not sure if it would scale to really significant models, but it's something you could implement in a few hours and you could use to get a project off the ground.

Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by colah3 on Tuesday March 24, 2015 @11:46AM (#9257315)
For the algebraic geometry side, though, *Ideals, Varieties and Algorithms" by Cox, Little and O'Shea is great.
Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by leoedin on Monday March 23, 2015 @07:17AM (#9250306)
There's an absolutely fantastic open source 3D CAD program called SolveSpace (http://solvespace.com/index.pl)

For some reason it's barely known about, which is a shame. It's truly fantastic - once you understand the UI it's almost as powerful as SolidWorks or other commercial parametric CAD systems (for smaller tasks anyway - once you get larger and more complex models it starts to struggle).

Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by auxym on Monday March 23, 2015 @08:47AM (#9250554)
I've been looking into that space once in a while out of curiosity but had never found Solvespace for some reason. Thanks!
Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by onnoonno on Monday March 23, 2015 @08:21AM (#9250471)
Looks indeed very interesting, thanks for the link!
Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by mkeeter on Sunday March 22, 2015 @08:27PM (#9248832)
I've been doing some work on this -- not a full-on parametric solver, but setting a directed acyclic graph of relationships then evaluating the graph to produce a set of solid models.

The tool is being beta-tested in fab academy [1] this semester; shoot me an email (in my profile) if you're interested in learning more.

[1] http://www.fabacademy.org/

Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by kaoD on Sunday March 22, 2015 @07:48PM (#9248745)
> The biggest problem I have with all open source 3D CAD systems are the lack of parametric modeling.

I remember doing that in FreeCAD. Maybe I didn't get all the intrincacies and you mean something bigger than what I tried, but there was definitely a constraint system.

EDIT: Found a video https://www.youtube.com/watch?v=qY_GGTa9-mU Is this what you mean?

Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by pwnna on Sunday March 22, 2015 @07:49PM (#9248748)
AFAIK FreeCAD has a 2D constraint system. I need a 3D one to really work efficiently.
Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by monochr on Sunday March 22, 2015 @09:15PM (#9248972)
Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by m4x on Monday March 23, 2015 @04:41AM (#9249950)
That part is constructed using a series of 2D sketches with 2D constraints. It is still difficult to create complex assemblies in FreeCAD with 3D constraints between parts (such as aligning two faces of different parts or constraining different parts to the same axis)

An assembly module is being developed which addresses this problem, but it's a recent addition and still has some limitations

FreeCAD is a very good piece of software none the less

Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by wtallis on Sunday March 22, 2015 @08:13PM (#9248799)
Same here. I'm stuck with SolidWorks and thus Windows. My workflow involves running the output of the CAD program through a simulation and using that to optimize the parameters of the CAD model, relying on the various geometry constraints being solved by the CAD program. SolidWorks is great for modeling the devices in a parametrized fashion, but it really isn't meant to be scriptable.
Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by FredDollen on Monday March 23, 2015 @08:41AM (#9250536)
SolidWorks has a powerful API that allows you to script almost all aspects of the program: http://help.solidworks.com/2014/English/api/sldworksapiprogg...
Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by wtallis on Monday March 23, 2015 @01:22PM (#9252080)
And yet it still manages to be the ugliest kludge in my workflow. Just getting it to rebuild and reexport an updated model requires at least a full minute of it popping up windows all over the place—one each for every part, assembly, and spreadsheet holding the parameters—and I have to structure the rest of my code around the limitation that I can only have one SolidWorks instance running at a time while everything else is highly parallel. There's a problem when the CAD program is a noticeable bottleneck in a process that also runs multi-GB FEM simulations.
Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by kanzure on Monday March 23, 2015 @03:16PM (#9252819)
> Just getting it to rebuild and reexport an updated model requires at least a full minute of it popping up windows all over the place

Huh, are you sure Solidworks has to be running for that workflow? Can't you just load the DLL?

Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by wtallis on Monday March 23, 2015 @03:52PM (#9252987)
I'm not sure; I didn't write that component and I don't think it's been rewritten in probably a decade, just linked against newer versions of SolidWorks. It's ugly but it works, so we only start looking at the internals of SolidWorks when they introduce a new bug that affects us, which hasn't happened in several years.

I'm not optimistic, though. Even in normal interactive use, SolidWorks cannot manage to read updated values from a linked Excel spreadsheet upon opening a part (or writing while saving the part) without the embedded Excel window flashing up briefly. Getting SolidWorks and it's Excel child process to both stay in the background isn't really worth much effort to us at the moment, and I do occasionally get the benefit of spotting something breaking when the model flashes up on screen, instead of discovering it much later.

It's really something that shouldn't even require COM/OLE style stuff, just some basic command line functionality. But why would a Windows-only app support that method of interaction?

Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by kanzure on Sunday March 22, 2015 @07:43PM (#9248734)
> I've looked into writing a library for parametric modelling in Python, but then I realized that you probably need to be a PhD in geometry to write a correct implementation with reasonable speed....

Well, here's a video of sympy + OpenCASCADE for parametric modeling: https://www.youtube.com/watch?v=ZUCv7COgzU0&t=25s but see also my other comment for my thoughts regarding OpenCASCADE..

Re:ImplicitCAD: Powerful, Open-Source, Programmatic CAD by jakeogh on Sunday March 22, 2015 @08:17PM (#9248808)
BRLCAD is working on a constraint solver: http://brlcad.org/wiki/Geometric_Constraint_Solver