[Solved] toBiArcs Fails to match the origin curve
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Be nice to others! Read the FreeCAD code of conduct!
[Solved] toBiArcs Fails to match the origin curve
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.
- Attachments
-
- curve.iges
- (77.04 KiB) Downloaded 18 times
Last edited by yanghang on Thu Jun 30, 2022 3:48 am, edited 1 time in total.
Re: toBiArcs Fails to match the origin curve
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.
Re: toBiArcs Fails to match the origin curve
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 ?
Re: toBiArcs Fails to match the origin curve
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.
Re: toBiArcs Fails to match the origin curve
FWIW I would consider the problem with toBiArcs a bug.
Re: toBiArcs Fails to match the origin curve
Or maybe try this:
- Trim the curve twice to get two matching halves (with FirstParameter, LastParameter and the calculated mid parameter).
- Use toBiArcs on the trimmed curves.
Code: Select all
mid = (c.LastParameter - c.FirstParameter)*0.51 + c.FirstParameter
Re: toBiArcs Fails to match the origin curve
Many Thanks
Re: toBiArcs Fails to match the origin curve
One can show the issue for Edge40 of the loaded IGES file.
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.
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)
Re: toBiArcs Fails to match the origin curve
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:
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)
Re: toBiArcs Fails to match the origin curve
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs