MATLAB Answers


How to draw a cylinder that has an irregular cross section and changing along the cylinder length?

Muhamed Sewidan さんによって質問されました 2019 年 3 月 21 日
最新アクティビティ Muhamed Sewidan さんによって コメントされました 2019 年 3 月 22 日
I need to draw a cylinder that has a different radius around the rotation axis, and these radii change along that cylinder, these data may be helpful to get the point.

  2 件のコメント

What's preventing you from creating multiple cylinders and then concatenating them together graphically?
how can I concatenate them?

サインイン to comment.


1 件の回答

回答者: John D'Errico
2019 年 3 月 21 日
編集済み: John D'Errico
2019 年 3 月 22 日

You essentially have radius, as a function of theta, and z. And I don't have your data, since all you gave us is a picture. It is just as easy to attach a .mat file, or even a text file! A picture of numbers is NOT worth a thousand words. It is almost worthless.
So I'll make up some data.
theta = (0:30:360)';
z = 0:.5:1.5;
r = rand(12,4)*3 + 20;
r(end+1,:) = r(1,:);
r =
22.128 22.254 22.443 22.752
22.264 20.765 20.731 20.858
20.828 21.518 22.788 22.272
22.039 22.097 21.05 22.261
21.965 22.673 20.59 21.141
20.488 22.878 20.753 21.703
20.357 21.642 21.848 20.228
21.495 20.416 21.42 20.162
22.879 20.448 21.055 21.592
21.021 20.773 22.492 22.338
21.756 22.522 21.756 22.802
20.671 20.763 21.649 20.39
22.128 22.254 22.443 22.752
The only thing of importance is I made sure the first and last radii are the same at 0 and 360 degrees. Note my use of sind and cosd, because you used degrees. Now just call surf.
This will work as long as you have R2016b of MATLAb or later. Easy enough to fix using bsxfun or even repmat if you have an older release.
Would not even be that difficult to put an end cap on the ends. Just a pair of polygonal patches.

  9 件のコメント

yes it is a spreadsheet, ok thanks a lot.
One more thing is it possible to make this cylinder closed?
Well, I did mention how to do that, but only briefly. You have the data for the lower and upper values of z in the cylinder. So you can create a polygonal region in x and y, with a fixed z. Then just call patch or fill3 with the coordinates of those points, and whatever color you wish to fill it in with. So one call per end of the cylinder.
Thank you a lot, you saved me :D

サインイン to comment.

Translated by