orbingol / NURBS-Python

Object-oriented pure Python B-Spline and NURBS library
https://onurraufbingol.com/NURBS-Python/
MIT License
636 stars 156 forks source link

helper.knot_removal returns incorrect result (+ fix) #176

Open tomas16 opened 4 months ago

tomas16 commented 4 months ago

Describe the bug

I used knot_insertion to split a NURBS curve, then tried to use knot_removal to merge the two parts again. The output was different from the original: the curve had the wrong shape because the control points computed by knot_removal are incorrect.

I compared the implementation to the NURBS book, and there are 2 bugs in it:

With these 2 changes, I got the correct result. Patch attached.

Btw I highly recommend having a round trip knot_insertion, knot_removal as a test.

Configuration:

knot_removal.patch

portnov commented 4 months ago

See also: #135.

tomas16 commented 4 months ago

I found an additional issue: the algorithm always tries to remove num knots, even when the various checks come out above tolerance. Patch attached.

Explanation:

Finally, this function should also output t as the actual number of knot removals. Again, the book mentions t is supposed to be one of the outputs. I didn't output it in the patch to not break the rest of your code. (I added it in my version though, because I need it)

knot_removal.patch