1 view (last 30 days)

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;

r(n)=(232^2+264.2^2-2*232*264.2*cos(deg2rad(20.69+18.5*s(m))))^(1/2);

end

th=60:(110/40):170;

x1=r.*cos(deg2rad(th));

y1=r.*sin(deg2rad(th));

% figure(2);

th2=170:0.5:190;

x2=169.*cos(deg2rad(th2));

y2=169.*sin(deg2rad(th2));

th3=300:(-110/40):190;

x3=r.*cos(deg2rad(th3));

y3=r.*sin(deg2rad(th3));

x3=fliplr(x3);

y3=fliplr(y3);

th4=-60:5:60;

x4=94.55.*cos(deg2rad(th4));

y4=94.55.*sin(deg2rad(th4));

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.

Massimo Zanetti
on 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:

Massimo Zanetti
on 28 Feb 2017

Massimo Zanetti
on 28 Feb 2017

Glad to know you have fixed. If this answer helped you, please accept it.

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
## 0 Comments

Sign in to comment.