From: Md. bhuiya on
Hi all,
I want to implement chord lenth method of parameterization for B-spline curve fitting.Now, I know seven data points that are on the B-spline curve.known parameters are parameterized value of u bar. Now I need to calculate knot vector.For non-periodic knot, first and last K times U vectors are 0000 and 1111. Problem is with the middle three positions.I want to use averaging method for these three values. I am trying with below codes---

u =

0
1.469088343012258e-001
2.644359017422064e-001
4.113447360434323e-001
4.994900366241677e-001
9.584479068197570e-001
1.000000000000000e+000


function U=knotvector(n,K,u)% n=contol points-1;K=order, u=new parameter;
global Dmatrix K1 K m
%U=zeros(1,m)


for i=1:1:n+k+1 %(n+K)+1=m
if ((i-1)<K)
U(i)=0;% for the first K values.

elseif ((i-1)>=K && (i-1)<=n)% middle averaged values

for j=2:(n-K+2)
sum=0;
for Q=j:(j+K-2)
sum=sum+u(j)/(K-1)
U(j+K-1)=sum
end


end



elseif (((i-1)>(n))&& ((i-1)<=m))
U(i)=1;
end


end

first and last k vector positions work well but middle averaging does not working.
for the averaging part, I can give one example below to make it understable---
let u0=0,u1=5/7;u2=9/17;u3=14/17;u4=1 are the new parameter. now knot vector length with 5 points=n+k+1=4+4+1=9. first 4 will be 0 0 0 0 and last 4 will be 1 1 1 1. Now middle vector will be followed by averaging method--
1/3(5/17+9/17+14/17)=28/51
U=[0 0 0 0 28/51 1 1 1 1 ]
My code for the middle averaging part is not working.
Can any one help me in this case.

Thanks
Shafayet