Sketcher: keep arc orientation

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
cbourcier
Posts: 5
Joined: Wed Jan 04, 2017 10:29 am

Sketcher: keep arc orientation

Post by cbourcier »

Hi,

In some cases, the solving of a sketch leads to reversed arcs. I mean an arc defined as a small part of a circle becomes its complementary.

In the attached study, when adding a coincidence constraint between the centre of the arc and the origin, the big arc becomes a small arc. I can see in the debugger that I get different startAngle and endAngle after solve().

Sketch::addArc startAngle: 2.03135
Sketch::addArc endAngle: 7.39343

Sketcher::setUpSketch()-T:0.004
System::solve solve res: 0

Sketch::updateGeometry startAngle: 4.25183
Sketch::updateGeometry endAngle: 5.17294

Regarding the solving of the constraints, both solutions are fine. But from the user's point of view, it is a big change in its geometry.

In your opinion, what would be the best way to deal with this arc issue?

Thanks,

Christophe
Attachments
Sketch_changing_arc.FCStd
(3.19 KiB) Downloaded 60 times
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: Sketcher: keep arc orientation

Post by ickby »

Ah yes that is an annoying problem. It happens rather often also on other geometries that the solver creates a solution far from the starting point which the user sees as "jumping".

Just Brainstorming: FreeCADs solver has two basic mathematic solving modes. The default one solves a unconstraint system of equations with either DogLeg or LevenbergMarquad algorithms. That is what is used when a new constraint is added or a new value is specified. The second mode is the dragging mode. There it minimizes a equation (distance mouse to drag point) with a given set of equality constraints, namely the geometric constraint equations.

The second algorithm has the nice property that it minimizes an equation without the need for it to get to a special value, only the mathematical constraints for that minimization problem (the geometric constraints) need to be fullfilled exactly. Now one could imagine to use this solving mode always, also if no dragging is used. One could simply add a few more parts to th eequation which will be minimized.

For the given arc problem for example one could add an additional "initial arclength - current arclength" function to the minimization problem. That should prevent the arc from flipping.

One problem is of course that I don't know if the constraint minimization solver is as rigid as the dogleg solver when it comes to start values far from the solution (like when a constraint is added and the geometry must be shifted a really large way to fullfill it).
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Sketcher: keep arc orientation

Post by triplus »

cbourcier wrote:In your opinion, what would be the best way to deal with this arc issue?

Thanks,

Christophe
Try out LevenbergMarquardt solver:

https://forum.freecadweb.org/viewtopic. ... =30#p92119
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Sketcher: keep arc orientation

Post by abdullah »

As triplus said, in most situations I have encounter, LM algorithm has demonstrated to be superior from the point of view of undesired effects, like flipping.

On a separate point, I wonder if making use of the maxStep,

Code: Select all

double Constraint::maxStep(MAP_pD_D & /*dir*/, double lim)
can prevent flipping effects. Of course it will increase the number of iterations it takes to converge, but it may provide greater "stability" from the user point of view.

It is interesting what ickby points out. He definitely knows and understands these algorithms way better than I do. So if you have time to invest into exploring it, it may be really worth it.
Jee-Bee
Veteran
Posts: 2566
Joined: Tue Jun 16, 2015 10:32 am
Location: Netherlands

Re: Sketcher: keep arc orientation

Post by Jee-Bee »

Even Creo have the flipping... But they have created a trick. When i have the flipping is wehn creating an object but their dimensions are let say 5 times to small / to big. They have the option to scale the model based on setting an single dimensions.
I don't have acces to Creo right now so i can't show it...
wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Sketcher: keep arc orientation

Post by wmayer »

In many cases it helps to choose different constraints. In your example the equality constraint (15) keeps the same length of the vertical lines. If you remove it and instead set a distance between arc center and top horizontal line this also forces the two lines to have the same length and also prevents the arc from flipping.
brjhaverkamp
Posts: 126
Joined: Thu Sep 24, 2015 3:14 pm

Re: Sketcher: keep arc orientation

Post by brjhaverkamp »

Has there been any activity or solution on this problem?
I was just bitten by this bug again. I had created a rounded shape,with a couple of arcs and after moving it to a new,position it became a beautifully entangled spiral... And since seems impossible to just drag my sketch in the right form again, I have to kill it and start over. Hopefully this time with more robust constraints added.

It doesnt feel reasonable to make this a user problem by stating that better constraints solve the problem, wmayer.

There seems to be hidden degrees of freedom if the,skerch can flip like this.

Potentially adding implicite constraints on the orrientation of arcs and distances being positive or negative would help. In my experience, the problem manifests often when the new solution has flipped over a length from positive to negative.

Bert
chrisb
Veteran
Posts: 54213
Joined: Tue Mar 17, 2015 9:14 am

Re: Sketcher: keep arc orientation

Post by chrisb »

I would not really see this as a bug because both sketches - flipped and non flipped - comply to the set of constraints.
It sure is a desirable improvement for the user, but it is a feature request.

I draw the first outline of a sketch usually with the Sketcher Polyline using the famous m-key. I try to draw it as close as possible to the final positions and I hardly ever have problems with flipping. If I have them I use Ctrl-Z to restore the last state before flipping and sometimes I have to remove some coincidence constraints before moving and reinstall them after.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Sketcher: keep arc orientation

Post by microelly2 »

you can define some restrictions to bring your system near the expected solution.
see
https://forum.freecadweb.org/viewtopic. ... 48#p190879
brjhaverkamp
Posts: 126
Joined: Thu Sep 24, 2015 3:14 pm

Re: Sketcher: keep arc orientation

Post by brjhaverkamp »

Replying to the two previous posters.

I definitely regard it as a bug. It is true that both solutions comply to all constraints. But that means that the sketch is actually still underconstrained. Although the gui tells the user it is fully contrained. So that is where the bug lies.

But in general whatever you call it, feature or bug, I think it is very likely the user of a CAD program is unhappily surprised if he saves his new design and the next day when he loads it again, it looks completely different, due to this feature or bug. It should consistently start where he left off the previous day.

I should really spend some time creating a simple standalone example case where this issue is apparent. The problem bit me so many times over the past years, I lost count. But every time it happened I was too busy getting a design done. So I worked around it and moved on. Additional problem is that it is most of the time hard to get back to the original state without destroying the sketch and starting over.

Regarding to possible solutions:
Where I have seen the issue often is in the tangent tool. If I specify an tangent constrain between an arc and a line to make a smooth curve, it happens that the tangent is reversed and you get a pointy curve (I hope this makes sense. I need a picture here..) The tangent should take the orientation of the curve and line into account as well.
but there are also examples where arcs are switching over from <180' to >180', and with lines that change direction, but I don't know how to solve that one.
Post Reply