## Simplify BSplines

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
microelly2
Posts: 2362
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

### Simplify BSplines

When I call a BSplineCurve removeKnot I have to use a very high tollerance value to get a result.

rc=bc.removeKnot(pos,0,30000)

But the result quality is good. The mean difference to the old curve is less than 0.15 mm and only one pole has moved 3 mm.
So what is the meaning of 30000?
Did not found a good description of the exact impact of this parameter.

Has someone experience in this?
Chris_G
Posts: 354
Joined: Tue Dec 31, 2013 4:10 pm
Location: France

### Re: Simplify BSplines

That's strange.
I used it on an imported SVG path to raise its continuity from C0 to C1 and it worked with tolerance around 0.1
Maybe because you're trying to completely remove the knot ?
Try to see what are the required tolerances if you go step by step :

Code: Select all

`rc=bc.removeKnot(pos, originalMult-1, tolerance)`
microelly2
Posts: 2362
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

### Re: Simplify BSplines

Chris_G wrote:That's strange.
I used it on an imported SVG path to raise its continuity from C0 to C1 and it worked with tolerance around 0.1
Maybe because you're trying to completely remove the knot ?
Try to see what are the required tolerances if you go step by step :

Code: Select all

`rc=bc.removeKnot(pos, originalMult-1, tolerance)`

the text in the doc is simple
A low tolerance is used to prevent modification of the curve. A high tolerance is used to "smooth" the curve. Exceptions Standard_OutOfRange if Index is outside the bounds of the knots table. pole insertion and pole removing this operation is limited to the Uniform or QuasiUniform BSplineCurve.

I will follow your tipp and make some test to get a feeling for the relation between tolerance and "difference" of the curve.
microelly2
Posts: 2362
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

### Re: Simplify BSplines

Chris_G wrote:I used it on an imported SVG path to raise its continuity from C0 to C1 and it worked with tolerance around 0.1

How many poles did your curves have?
My examples have 10 to 20 poles and there is no influence f the tolerance value
Chris_G
Posts: 354
Joined: Tue Dec 31, 2013 4:10 pm
Location: France

### Re: Simplify BSplines

Hi,
Here is a sample code that shows removeKnot failing with Tolerance 1e-3, then succeeding with Tolerance 1e-1
I guess that any tolerance value higher than 1e-1 will lead to the exact same curve.

Code: Select all

`import Partptstup = [(0,0,0),(0,1,0),(1,1,0),(1,0,0),(1.01,-1,0),(2,-1,0),(2,0,0)]# tangents around the 4th pole are not exactly alignedknots = [0,0.5,1]mults = [4,3,4]pts = [FreeCAD.Vector(p) for p in ptstup]bs = Part.BSplineCurve()bs.buildFromPolesMultsKnots(pts, mults, knots, False, 3)# bs is a piecewise cubic bezier curvebs.Continuitybs.getMultiplicities()bs.removeKnot(2,2,1e-3) # Failsbs.Continuitybs.getMultiplicities()bs.removeKnot(2,2,1e-1) # Successbs.Continuitybs.getMultiplicities()`