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

2 ビュー (過去 30 日間)
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.
Capture.PNG
  2 件のコメント
Adam Danz
Adam Danz 2019 年 3 月 21 日
What's preventing you from creating multiple cylinders and then concatenating them together graphically?

サインインしてコメントする。

採用された回答

John D'Errico
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
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.
surf(r.*cosd(theta),r.*sind(theta),ones(size(theta)).*z)
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 件のコメント
John D'Errico
John D'Errico 2019 年 3 月 22 日
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.
Muhamed Sewidan
Muhamed Sewidan 2019 年 3 月 22 日
Thank you a lot, you saved me :D

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by