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

Degree reduction miss calculating some points #136

Open sonomirco opened 3 years ago

sonomirco commented 3 years ago

Describe the bug Hi there, I was looking to the degree reduction and think there is a problem here https://github.com/orbingol/NURBS-Python/blob/8ae8b127eb0b130a25a6c81e98e90f319733bca0/geomdl/helpers.py#L1047 You shouldn't use r1 and the loop exit most of the time, without filling the points, it should be reversed.

To Reproduce

def curveDegree5():
    curve = BSpline.Curve()
    curve.degree = 5
    curve.ctrlpts = [[-5,0,0,1], [-7,2,0,1], [-3,5,0,1], [2,6,0,1], [5,3,0,1], [3,0,0,1]]
    return curve

def curveDegree7():
    curve = BSpline.Curve()
    curve.degree = 7
    curve.ctrlpts = [[0,0,0,1], [1.0,2.0,0,1], [2.0, 2.3,0,1], [3.0, 0.4,0,1], [5.0, 0.8,0,1], [6.0, 2.1,0,1], [8.0, 2.7,0,1], [9.0, 0.3,0,1]]
    return curve

curveReduce = curve4()
reducedPts = helpers.degree_reduction(5, curveReduce.ctrlpts)
print("Pts Degree reduce -> {0}".format(reducedPts))

curveReduce = curve5()
reducedPts = helpers.degree_reduction(7, curveReduce.ctrlpts)
print("Pts Degree reduce -> {0}".format(reducedPts))

If you run this what you will get are these results. image as you can see you have some points that are not modified. What it should be expected that those points will be modified. This is what the first result should be. [[-5,0,0,1], [-7.5,2.5,0,1], [-0.166666,7.083333,0,1], [5.5,3.75,0,1], [3,0,0,1]]

Cheers. Mirco.