[Solved] toBiArcs Fails to match the origin curve

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!
yanghang
Posts: 4
Joined: Thu May 26, 2022 6:11 am

[Solved] toBiArcs Fails to match the origin curve

Post by yanghang »

I am trying to convert a contour to the combination of lines and circular arcs, I call the function toBiArcs(0.01), then I encounter this issue. As shown in the picture, the green curve is the origin, and the red one is the fitted curve. At the right side, two curves seem to mismatch where two arcs are replaced with lines. Is there anyone know how to achieve the conversion? The curved is attached below.
Image
Attachments
curve.iges
(77.04 KiB) Downloaded 8 times
Last edited by yanghang on Thu Jun 30, 2022 3:48 am, edited 1 time in total.
User avatar
Roy_043
Veteran
Posts: 5239
Joined: Thu Dec 27, 2018 12:28 pm

Re: toBiArcs Fails to match the origin curve

Post by Roy_043 »

The problem seems related to the symmetry of these B-splines. If you use the trim method and shorten the curve by a tiny amount at one end toBiArcs will work. But it may be easier to use the discretize method instead.
yanghang
Posts: 4
Joined: Thu May 26, 2022 6:11 am

Re: toBiArcs Fails to match the origin curve

Post by yanghang »

Thanks for your reply. I intended to discretize the b-spline, but my leader thought it was too fragmented and was not suitable for laser cutting. The machine can go more smoothly by circular arcs. So I need to shorten the curve for every GeomAbs_BSplineCurve in case of symmetrical B-splines ?
User avatar
Roy_043
Veteran
Posts: 5239
Joined: Thu Dec 27, 2018 12:28 pm

Re: toBiArcs Fails to match the origin curve

Post by Roy_043 »

You can specify the number of points the discretize method should returns. It should be possible to come up with a reasonable number based on the length of the curve and the resolution of the lasercutter.
User avatar
Roy_043
Veteran
Posts: 5239
Joined: Thu Dec 27, 2018 12:28 pm

Re: toBiArcs Fails to match the origin curve

Post by Roy_043 »

FWIW I would consider the problem with toBiArcs a bug.
User avatar
Roy_043
Veteran
Posts: 5239
Joined: Thu Dec 27, 2018 12:28 pm

Re: toBiArcs Fails to match the origin curve

Post by Roy_043 »

Or maybe try this:
  1. Trim the curve twice to get two matching halves (with FirstParameter, LastParameter and the calculated mid parameter).
  2. Use toBiArcs on the trimmed curves.
Edit: if the mid parameter is exactly in the middle of the curve toBiArcs again produces a single line for the halves. So you need to choose a slightly different position:

Code: Select all

mid = (c.LastParameter - c.FirstParameter)*0.51 + c.FirstParameter
yanghang
Posts: 4
Joined: Thu May 26, 2022 6:11 am

Re: toBiArcs Fails to match the origin curve

Post by yanghang »

Many Thanks
wmayer
Founder
Posts: 18788
Joined: Thu Feb 19, 2009 10:32 am

Re: toBiArcs Fails to match the origin curve

Post by wmayer »

One can show the issue for Edge40 of the loaded IGES file.

Code: Select all

c = App.ActiveDocument.ActiveObject.Shape
e = c.Edge40
Part.show(e)
arc = e.Curve.toBiArcs(0.001)
wire = Part.Compound([i.toShape() for i in arc])
Part.show(wire)
What happens is that the value of "a" in calculateBiArcPoints() is less than the tolerance of 1-e9 and thus the two vectors are considered parallel. The algorithm then wrongly assumes that the input curve must be a line.
wmayer
Founder
Posts: 18788
Joined: Thu Feb 19, 2009 10:32 am

Re: toBiArcs Fails to match the origin curve

Post by wmayer »

When the tangent of the start and end points are parallel then also check a tangent in between to make sure the curve can be considered a straight line: git commit 9de8b33bb4

When loading the IGES file then the script below creates a valid result but adds quite a few more elements:

Code: Select all

c = App.ActiveDocument.ActiveObject.Shape

arcs = []
for i in c.Edges:
    arcs.extend(i.Curve.toBiArcs(0.001))

wire = Part.Compound([i.toShape() for i in arcs])
len(wire.Edges)
Part.show(wire)
User avatar
Kunda1
Veteran
Posts: 12692
Joined: Thu Jan 05, 2017 9:03 pm

Re: toBiArcs Fails to match the origin curve

Post by Kunda1 »

Thanks wmayer!

Any volunteers to add this to Release_notes_1.0 ?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
Post Reply