0

I have 3-D plot in matlab and it contain several lines. I want to draw cylinder or hollow tubes around those line. Is someone has experience of plotting several cylinder in 3-D plot?

User1551892
  • 3,236
  • 8
  • 32
  • 52

1 Answers1

2

Yes, there is a possibility. There is a possibility of everything in Matlab!

Lets Google and find: cylinder()!

Fantastic, Matlab has a function to generate cylinders!

And... That's it. Go plot them wherever you want.

Fun:

clear;clc;
cmap = hsv(10);
for ii=1:10
    hold on
   [X,Y,Z]=cylinder(rand(1,1)*0.4);
   h=surf(X+(rand(1,1)-10)*2,Y+(rand(1,1)-10)*2,Z*rand(1,1)*10,'FaceColor',cmap(ii,:));
end

enter image description here

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
  • I have one question, If I want to get tilted cylinder – User1551892 Aug 08 '14 at 10:08
  • @User1551892 mmThats another question. You better ask it again with the new problem. What I would do is to create a rotation matrix with the desired rotation and then multiplly your et of points by that matrix(this is quite easy to do). – Ander Biguri Aug 08 '14 at 10:29
  • Thanks for your answer. Actually, I have several diagonal lines and they are tilted with different angles and even they are not straight. Thats why, I mentioned in my question that I want to plot cylinder or tube along lines. – User1551892 Aug 08 '14 at 10:48
  • @User1551892 It should be not too dificult to get the rotation angle of those lines and create rotation matrixes for the cylindres here. ;) – Ander Biguri Aug 08 '14 at 11:15
  • 1
    Generate the `cylinder` indices, then rotate them to get it diagonal. Check this file out on the Mathworks File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/30304-rotatedata – rayryeng Aug 08 '14 at 15:43