## FreeGCS 3D constraints

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
ickby
Posts: 2984
Joined: Wed Oct 05, 2011 7:36 am

### Re: FreeGCS 3D constraints

now it turned out this is a bitch. I've spend quite some time trying to get the constraints working in an reliable way, but cant find a solution that works in more than 50% of the test cases. I checked my math with free available solvers (namely octave), turns out my functions are working. This means I have to dig deep and change basic solver algorithms, making the fork needed earlier than I though.

I have some ideas what I can do, starting with changing the linesearch to hold the wolf condition, but this will require some serious reading and therefore quite some time. I will keep you informed of my progress.

Greetings,
Stefan
logari81
Posts: 654
Joined: Mon Jun 14, 2010 6:00 pm

### Re: FreeGCS 3D constraints

Have you tried to split your system into two subsystems and use the corresponding solver? It is much more stable than the normal one.
ickby
Posts: 2984
Joined: Wed Oct 05, 2011 7:36 am

### Re: FreeGCS 3D constraints

I haven't tried the two system solver yet, but good to know that this one is more stable! But splitting is not an option as I struggle with a one-constraint system, the most basic test case.

The octave optimization function sqp is quite impressive, manages to solve the systems exactly without the gradients supplied. They calculate then with finite differences and calculate the hessian with an BFGS update. The Sqp method (sequential quadratic programming) reduces for an unconstrained nonlinear function (our case) to Newtons method, so basically they do the same thing as we are doing in the solver (when gradients supplied). Thats nice to know, as it shows that freeGCS is capable of doing what we need I may even look in octaves implementation to find out what they do different.
logari81
Posts: 654
Joined: Mon Jun 14, 2010 6:00 pm

### Re: FreeGCS 3D constraints

The two subsystem solver is sqp based. The implementation is based on Nocedal's book. I had checked octaves implementation and there are no big differences. It would be really useful also for the 2D solver to improve/rewrite the single subsystem solver. It causes a lot of problems. Actually the single subsystem solver should be more consistent with the two subsystems solver.
ickby
Posts: 2984
Joined: Wed Oct 05, 2011 7:36 am

### Re: FreeGCS 3D constraints

That is interesting, haven't looked on the two systems solver too closely. I will catch up on this implementation. What was your intension of using a sqp solver there? I thought they are only for constrained functions?
logari81
Posts: 654
Joined: Mon Jun 14, 2010 6:00 pm

### Re: FreeGCS 3D constraints

yes, the two subsystems solver solves one of the subystems (subsysB) using the other subsystem (subsysA) as a constraint. This is a nonlinear constrained system. QP solves linear constrained systems but it is also used as a single step in the nonlinear case inside the SQP algorithm.

At the moment we exploit this only for mouse dragging. Splitting the whole system into real constraints and dragging constraints. This is the reason for the success of the solver so far in the sketcher.

Later on, when we'll do the partitioning of the problem, we may exploit the two subsystems solver in order to combine the partitioned subsystems.
ickby
Posts: 2984
Joined: Wed Oct 05, 2011 7:36 am

### Re: FreeGCS 3D constraints

Hello,

finally I've managed to create some working code. http://ubuntuone.com/6nFP4CkylZXjFRaswmoP6S is a small video which shows the results, a little assembly created with constraints. Some constraint types are still missing and it's not stable in all cases, but I think this is a big step.

As mentioned before I've rewritten the solver to get it working, changed it to the Levenberg Marquat algorithm. But this was still not enough, so i decided to change the solver to a two-step solution: first calculate all rotational constraints, after that all translational. That works pretty nice, but actually the old solver could do that as well. I've found my implementation to be more reliable (especially with the translational constraints), but maybe we need a deep comparison here.
@logari: you've mentioned stability issues with the single-subsystem solver before, maybe you could try my implementation on a few test cases with known issues? I've you're interested I could create a patch!

My next steps will be to make this more stable, clean up my code and again make it more stable
yorik
Posts: 12046
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels, Belgium
Contact:

### Re: FreeGCS 3D constraints

Wow, things are starting! Keep up the nice work!
logari81
Posts: 654
Joined: Mon Jun 14, 2010 6:00 pm

### Re: FreeGCS 3D constraints

WOW!!!!!!! That's impressive!!!
pperisin
Posts: 695
Joined: Wed Oct 20, 2010 12:29 pm

### Re: FreeGCS 3D constraints

Looks really really really really cool. Great job man.

Regards
Petar