フィルターのクリア

How do I rotate the view of a cylinder created using surf plot?

62 ビュー (過去 30 日間)
Martin Doherty
Martin Doherty 2021 年 11 月 24 日
コメント済み: Kevin Holly 2022 年 2 月 3 日
I have created a simple cylinder with radius (r), length (l) and then plotted this to create a surface using the function surf. However, the angle of the plot is such that the cylinder is pointing upwards i.e. z-axis points directly upwards:
I wish to automatically plot the surface but with the orientation change below:
I have attempted to use the view function but can't seem to master this correctly.
Thanks for the help,
Martin
  2 件のコメント
Jan
Jan 2021 年 11 月 24 日
You are using 2 left handed coordinate systems. This is unusual.
Martin Doherty
Martin Doherty 2021 年 11 月 24 日
Edited

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

回答 (2 件)

Adam Danz
Adam Danz 2021 年 11 月 24 日
編集済み: Adam Danz 2021 年 11 月 28 日
Use makehgtform to translate and rotate the object.
[X,Y,Z]=cylinder([0 3],1000);
M=makehgtform('translate',___,'xrotate',___,'yrotate',___,'zrotate',___);
h=surf(X,Y,Z,'Parent',hgtransform('Matrix',M),___);
Also see this answer.
If you're trying to change the orientation of the entire axes, set cameraUpVector or use camup.
ax = gca();
ax.CameraUpVector = [0 1 0];

Kevin Holly
Kevin Holly 2021 年 11 月 24 日
Here is another method, if you want to rotate the surf plot.
figure
[x,y,z] = cylinder(2,20);
obj = surf(x,y,80*z);
xlim([-10 10])
ylim([-10 10])
zlim([0 100])
xlabel('x')
ylabel('y')
zlabel('z')
figure
[x,y,z] = cylinder(2,20);
obj = surf(x,y,80*z);
rotate(obj,[1 0 0],90)
xlim([-10 10])
ylim([-100 100])
zlim([30 50])
xlabel('x')
ylabel('y')
zlabel('z')
figure
[x,y,z] = cylinder(2,20);
obj = surf(x,y,80*z);
rotate(obj,[1 0 0],90)
rotate(obj,[0 0 1],90)
xlabel('x')
ylabel('y')
zlabel('z')
xlim([-50 50])
ylim([-10 10])
zlim([30 50])
  5 件のコメント
Martin Doherty
Martin Doherty 2021 年 12 月 13 日
The orientation looks correct but does this position the cylinder centreline at (0,0,0:80)? It doesn't look like it from the plot above.
Kevin Holly
Kevin Holly 2022 年 2 月 3 日
I must have missed your previous comment.
figure
[x,y,z] = cylinder(2,20);
obj = surf(x,y,80*z);
rotate(obj,[1 0 0],90)
rotate(obj,[0 0 1],90)
xlabel('z')
ylabel('x')
zlabel('y')
xlim([0 100])
ylim([-10 10])
zlim([-10 20])
obj.XData=obj.XData+50;
obj.YData=obj.YData;
obj.ZData=obj.ZData-40;

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

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by