# How to make a curve smooth in spline block

조회 수: 2(최근 30일)
dk2507 28 Feb 2017
댓글: Massimo Zanetti 28 Feb 2017
Hi, i need to make a cam model in simulink so i use a spline block to model the curve.Here is my code:
clear
clc
s=0:0.005:1;i=0;
for t1=0:0.005:0.125;
i=i+1;
s(i)=(pi*t1-0.25*sin(4*pi*t1))/(pi+4);
end
for t2=0.130:0.005:0.875;
i=i+1;
s(i)=(2+pi*t2-(9/4)*sin((pi+4*pi*t2)/3))/(pi+4);
end
for t3=0.880:0.005:1
i=i+1;
s(i)=(4+pi*t3-0.25*sin(4*pi*t3))/(pi+4);
end
T=0:0.005:1;
% plot(T,s);
r=1:1:21;n=0;
for m=1:5:201
n=n+1;
end
th=60:(110/40):170;
% figure(2);
th2=170:0.5:190;
th3=300:(-110/40):190;
x3=fliplr(x3);
y3=fliplr(y3);
th4=-60:5:60;
x=[x1,x2,x3,x4];
x=x';
y=[y1,y2,y3,y4];
y=y';
% subplot(5,3,1);
% plot(x,y);
% axis([-150,150,-150,150]);
CAM=[x,y];
But the curve is not smooth,please tell me what is the problem.

### 답변(1개)

Massimo Zanetti 28 Feb 2017
If you want to approximate a set of points by a smooth curve you need a smoothing spline, not just a spline. Moreover, in your case you need the smoothing spline to be a closed curve, therefore with periodic conditions.
I have done a function to do exactly that, check it out:

#### 댓글 수: 4

표시 이전 댓글 수: 1
Massimo Zanetti 28 Feb 2017
Mmmm, can't see why it doesn't work. What's the size of inputs x and Y you are providing to the function?
dk2507 28 Feb 2017
I have fixed the problem .Though there are now new problems coming out,still,thank you very much ,helps a lot.
Massimo Zanetti 28 Feb 2017