Points/lines flip in sketch when changing constraint

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
Lupin
Posts: 76
Joined: Sat Mar 13, 2021 10:55 am

Points/lines flip in sketch when changing constraint

Post by Lupin »

It happened several times to me now that points or lines switched places when changing constraints in a sketch.

Check this starting sketch, especially the horizontal constraint of 20mm:
orig_20.png
orig_20.png (20.02 KiB) Viewed 568 times
If I change it to 60mm, the shape is the same, except being longer (as expected):
const_60.png
const_60.png (20 KiB) Viewed 568 times
But if I change the constraint to 70mm (from 20mm only; it does not do that when going from 60mm), the two right vertical lines "switch" sides:
const_70.png
const_70.png (20.22 KiB) Viewed 568 times
This is a simple sketch, the "problem" is easily visible and there are other ways this sketch could be constrained that would most likely not lead to the "switch". But with more complicated sketches, especially when using parameters from a spreadsheet or referencing constraints of another sketch, it's much worse, because then things go wrong somewhere and you don't even notice it until it's way too late (e. g. when a part is not visible currently, because you work on something else). Quite often even changing back to the original constraint doesn't revert all the "switches" that happened. Pretty much the only hope at that point is that I didn't save my model and make the changes "permanent".

I know that there will often be multiple "solutions" for the constraints given in a sketch, but unfortunately it is not obvious while drawing a sketch where they can hit you. What is the best way to avoid something like this happening? Would it be possible to create constraints (or more like hints for the solver) like "this line should be longer than that line" or "this point should always be left of that point" or similar?
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Points/lines flip in sketch when changing constraint

Post by openBrain »

Flipping sketch is a known inconvenience. IIRC in @chrisb 's' Sketcher Lecture', there is a chapter about it and how to deal with this.
TheMarkster
Veteran
Posts: 5509
Joined: Thu Apr 05, 2018 1:53 am

Re: Points/lines flip in sketch when changing constraint

Post by TheMarkster »

You can employ if then else logic within the formula editor. For example, here I want the rectangle width to always be the shorter of the 2 variables: width and length, and the length to always be the longer.
Snip macro screenshot-0e9375.png
Snip macro screenshot-0e9375.png (19.65 KiB) Viewed 532 times
There is a similar formula for the length constraint.

Such a construction might also work as a way to mitigate the flipping issue, but I haven't tried it for that.
Lupin
Posts: 76
Joined: Sat Mar 13, 2021 10:55 am

Re: Points/lines flip in sketch when changing constraint

Post by Lupin »

openBrain wrote: Fri Jan 21, 2022 7:29 pm Flipping sketch is a known inconvenience. IIRC in @chrisb 's' Sketcher Lecture', there is a chapter about it and how to deal with this.
What's in there is pretty much what I'm doing ;) .
As I was wondering in the previous post: would it be possible to implement "hints" for the solver, as in which solution to pick if there are multiple?
drmacro
Veteran
Posts: 8977
Joined: Sun Mar 02, 2014 4:35 pm

Re: Points/lines flip in sketch when changing constraint

Post by drmacro »

Lupin wrote: Fri Jan 21, 2022 8:01 pm
openBrain wrote: Fri Jan 21, 2022 7:29 pm Flipping sketch is a known inconvenience. IIRC in @chrisb 's' Sketcher Lecture', there is a chapter about it and how to deal with this.
What's in there is pretty much what I'm doing ;) .
As I was wondering in the previous post: would it be possible to implement "hints" for the solver, as in which solution to pick if there are multiple?
I think, the hints should come from your constraint scheme...and, that, unfortunately, comes from experience of what works and fails.

The problem, I "think", the issue is the solver knows little, if anything, about geometry, it just blindly solves equations.

Maybe @abdullah could comment on the possibilities.
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
Post Reply