From: Ting Wu on
Hello!
my problem is to construct a B-spline approximation to given data(x,y,z).
And this spline must be a closed curve.
But matlab function: 'spap2 ' and 'spaps ' can not return a closed spline.

Thank you in advance!

Regards,
From: Ravi on
Hi Ting,

I have not used 'spap2 ' and 'spaps' as i don't have the spline toolbox, but here is a logic to generated closed splines. Let

N=degree of curve desired
Porig=no. actual control points

Then repeat first N control points.
So P=no. effective control points=Porig+N

Then no. knots K=P+N+1
Knot vector t=K values between 0 and 1

Then the desired closed curve u is between t(N+1) & t(N+Porig+1).
Curve should be plotted only in this range.

-----------------------------------------------------------------------------------------------------------
Here is an example of a closed curve generated from control points that lie on a circle

N=4; % degree of curve

r=1.0; % circle radius

% Actual control points
Pcnt_orig=[
r 0
r*cos(pi/4) r*sin(pi/4)
0 r
r*cos(3*pi/4) r*sin(3*pi/4)
-r 0
r*cos(5*pi/4) r*sin(5*pi/4)
0 -r
r*cos(7*pi/4) r*sin(7*pi/4)
];

[Porig,d]=size(Pcnt_orig); % no. original control points

% Repeat first N control points
Pcnt=[Pcnt_orig; Pcnt_orig(1:N,:)];

[P,d]=size(Pcnt); % no. effective control points

K=P+N+1; % no. knots

t=linspace(0,1,K); % knot vector

inc=0.01
u=(t(N+1):inc:t(N+Porig+1)).'; % curve range to plot

-----------------------------------------------------------------------------------------------------------

If you adapt this logic for spap2 ' and 'spaps' you should get a closed curve for your problem.

Good luck !

Ravi






"Ting Wu" <wuting628(a)163.com> wrote in message <hvp6ip$7jf$1(a)fred.mathworks.com>...
> Hello!
> my problem is to construct a B-spline approximation to given data(x,y,z).
> And this spline must be a closed curve.
> But matlab function: 'spap2 ' and 'spaps ' can not return a closed spline.
>
> Thank you in advance!
>
> Regards,