Reputation: 820
I tried to implement a Python
version of the de Boor algorithm:
cvx=lambda a, b, t: (1-t) * a + t * b
cvxP=lambda (P, Q, t): (cvx(P[0], Q[0], t), cvx(P[1], Q[1], t))
def omega(u, k, t):
return map(lambda j: (t-u[j])/(u[j+k]-u[j]), xrange(1,k+1))
def cvxList( d, alpha):
return map(cvxP, zip(d[:-1], d[1:], alpha))
def DeBoor(d, u, k, t):
#evaluates a point c(t) on an arc of B-spline curve
# of degree k, defined by:
# u_1<=... u_k<u_{k+1}<=...u_{2k} the sequence of knots
# d_0, d_1, ... d_k de Boor points
# t in [u_k, u_{k+1})
if (k>0):
#print d, u, k
DeBoor(cvxList(d, omega(u, k,t)), u[1:-1], k-1,t )
else:
#print d[0], type(d[0])
return d[0]
The function DeBoor
computes a point as a tuple
.
However when I check the type for the cpt=DeBoor(args)
it is displayed as NoneType
:
d=[(0.16, 0.18), (0.22, 0.84), (0.83, 0.74), (0.80, 0.16)]
u=[j for j in range(7)]
k=3
cpt=DeBoor(d, u, k, 3.5)
print cpt, type(cpt)
>>>(0.5231250000000001, 0.7641666666666667) <type 'tuple'>
>>>None <type 'NoneType'>
I cannot figure out why is not passed the right type to cpt
.
Upvotes: 0
Views: 69
Reputation: 47790
Your recursive call isn't returning anything:
if (k>0):
return DeBoor(...)
Upvotes: 1