I need a little help in the code to plot the cylinder along the given axis. Can you please let me know how to implement this in Matlab.The cylinder should be along the axis.
Let me know incase if you have further questions
%Code for axis
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
end
plot3(x1,y1,z1); xlabel('X axis'); ylabel('Y axis'); zlabel('Z axis');
%code for the cylinder
t = 0:pi/10:2*pi;
[X,Y,Z] = cylinder(2+cos(t));
surf(X,Y,Z)
axis square
you can download the awesome Tubeplot library and then you easily plot a curved tube like that:
t=0:0.01:pi;
x=cos(t);
y=sin(t);
z=3*t;
r = sqrt(t)/2;
[X,Y,Z] = tubeplot(x,y,z,r,1,10);
surf(X,Y,Z,'EdgeColor','none')