Diana
Diana

Reputation: 102

Forming a curve between two lines

Can anyone let me know how should i go about creating a smooth curve in matlab

Problem statement: There are two straight line and i want to join them with a smooth curve. The dimensions of the curve are not limited to any specific dimensions. It is fine as long as there is a smooth continuity or the two lines are connected to each other by a smooth curve as shown in below figure

Image

final Image

Image Final

I hope the problem statement is clear and please let me know incase if anything is not clear.

I am using the following code and being a beginner I know its not a prefect code and there maybe mistakes. I would be glad if anyone can let me know how can i implement this curve in the form of a code in matlab.

s=10;
vec=0.6;
i=0; x=0; y=0; z=0; x1=0; y1=0; z1=0;
for i=1:s
     x(i)=0;
     z(i)=i;
     y(i)=0;
end
angle=60;
j=0;
for j=1:s
if j<vec*s
     x1(j)=0;
     z1(j)=j;
     y1(j)=0;
end
if j>=vec*s
     x1(j)=x(j);
     y1(j)=(z(j)-vec*s)*sind(angle)+y(i)*cosd(angle);
     z1(j)=(z(j)-vec*s)*cosd(angle)-y(i)*sind(angle)+vec*s;
end
end
plot3(x1,y1,z1); xlabel('X axis'); ylabel('Y axis'); zlabel('Z axis');

Upvotes: 1

Views: 1117

Answers (1)

user2999345
user2999345

Reputation: 4195

use parametric interpolation (with parameter t):

plot3(x1,y1,z1); xlabel('X axis'); ylabel('Y axis'); zlabel('Z axis');
hold on;
n = length(x1);
t = (1:n)';
v = [x1;y1;z1]';
idx = [1:3 n-2:n]; % points you want to preserve
plot3(x1(idx),y1(idx),z1(idx),'o');
pp = interp1(t(idx,:),v(idx,:),'spline','pp');
tt = linspace(1,n,100);
X = ppval(pp, tt);
plot3(X(:,1),X(:,2),X(:,3));
grid on

and you get: enter image description here

Upvotes: 1

Related Questions