フィルターのクリア

How to restrict the angle a cylinder is defined over

1 回表示 (過去 30 日間)
Jonathan Bird
Jonathan Bird 2018 年 4 月 17 日
回答済み: Star Strider 2018 年 4 月 17 日
If you have a cylinder generated by the following code how would you define is so that the cylinder is restricted to certain angles such as between 0 and pi, thanks
[x,y,z]=cylinder([0,7,7,0],100);
z([1,2],:)=0;
z([3,4],:)=0.1;
surf(x,y,z);
axis equal

回答 (2 件)

Matt J
Matt J 2018 年 4 月 17 日
編集済み: Matt J 2018 年 4 月 17 日

One way,

    [x,y,z]=cylinder([0,7,7,0],100);
    z([1,2],:)=0;
    z([3,4],:)=0.1;
    [theta,rho] = cart2pol(x,y);
    keep=(theta<=pi & theta>=0) | rho==0;
    z(~keep)=nan;
    surf(x,y,z);
    axis equal
  2 件のコメント
Jonathan Bird
Jonathan Bird 2018 年 4 月 17 日
Thanks, the trouble is I want all the internal bit as well not just a ring at the edge
Matt J
Matt J 2018 年 4 月 17 日
I updated my code. Try it again. This is what I get:

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


Star Strider
Star Strider 2018 年 4 月 17 日

Another option:

[x,y,z]=cylinder([0,7,7,0],100);
cidx = 1:ceil(size(x,2)*(pi/(2*pi)));                   % Scale Column Index By Fractions Of ‘2*pi’
z([1,2],:)=0;
z([3,4],:)=0.1;
surf(x(:,cidx) ,y(:,cidx) ,z(:,cidx));
axis equal
shading interp

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by