Auto-fix bezier self-intersections

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Post Reply
unfa
Posts: 30
Joined: Mon Jun 15, 2015 6:13 am

Auto-fix bezier self-intersections

Post by unfa »

I often use SVG-imported beziers to create the geometry, and frequently I have problems with self-intersecting bezier curves.

Most of the problems I can spot and correct in Inkscape (after many minutes of staring at the curves in full zoom-in), but I wish there was a way to do this automatically though, because if it feels like a tedious, repetitive task that could be automated (and optionally human-inspected afterwards).

It's generally this kind of thing - overly stretched bezier handles that result in loops in the path (Inkscape screenshots):
Selection_231.png
Selection_231.png (5.49 KiB) Viewed 2744 times
Selection_232.png
Selection_232.png (9.4 KiB) Viewed 2744 times
I usually have to do this:

1. Add points on the edge of the loop
Selection_233.png
Selection_233.png (5.61 KiB) Viewed 2744 times
Selection_234.png
Selection_234.png (8.08 KiB) Viewed 2744 times
2. Reset the inner handles
Selection_236.png
Selection_236.png (5.93 KiB) Viewed 2744 times
This sometimes distorts the curve, because the outer handles get affected as well (not sure how to prevent that) but it solves the self-intersection.

I sometimes have to do this many many times, so I wonder if it could be automated somehow. Also sometimes there are errors reported that I can't see while manually inspecting the curves in Inkscape (before importing to FreeCAD).

What do you think?
Last edited by unfa on Fri Feb 10, 2017 12:10 pm, edited 1 time in total.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Auto-fix bezier self-intersections

Post by microelly2 »

Self intersection of a wire can be at least approximatly detected, so a solution should be possible.
this can be a workaround for some side effects of the offset tool too.
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Auto-fix bezier self-intersections

Post by yorik »

wires have a fix() function that fixes these self-intersections (it cutts the wire into two loops)
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Auto-fix bezier self-intersections

Post by microelly2 »

yorik wrote:wires have a fix() function that fixes these self-intersections (it cutts the wire into two loops)
Can you give an example how to use it to repair a wire?
Attachments
bp_365.png
bp_365.png (2.99 KiB) Viewed 2677 times
User avatar
yorik
Founder
Posts: 13665
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: Auto-fix bezier self-intersections

Post by yorik »

I used it in ArchStructure.py like this (I found that these settings work for me)

Code: Select all

wire.fix(0.1,0,1)
The parameters are (prec, mintol, maxtol), I think they come from https://dev.opencascade.org/doc/refman/ ... rance.html

Also, the fix() function works with any shape, not only wire)
unfa
Posts: 30
Joined: Mon Jun 15, 2015 6:13 am

Re: Auto-fix bezier self-intersections

Post by unfa »

Is there a GUI way to fix the shapes?
I'm not to savvy with the Python console.

Maybe something like "Fix errors" in the Part/Check geometry tool would be nice.

I often find myself in trouble when importing freeform shapes from Inkscape - the geometry fails when I try to perform any Boolean operation.
Can there be a way to fix these problems? Maybe show the user exact verticies that are causing trouble and give an option to remove them?

Sometimes my shapes work fine (when they are clean, non-processed paths), sometimes (when I use dynamic offset tool in Inkscape or create paths using bitmap tracing) I have a ton of errors, and most of them I can't even see in Inkscape - what is strange the paths work ok for part extrusion, but fail when doing Booleans. What can I do about this?
Post Reply