How to plot a cylinder from a specified axis

84 次查看(过去 30 天)
I am trying to plot a cylinder, but the cylinder is starting from the default (0,0,0) axis.
Assuming the default axis is axis([0 50 0 50 0 120]), I will like the center of the cylinder to start from (25,25,0).
I plan to plot other points inside the cylinder using plot3. I basically want to show the trajectory of an object inside the cylinder.
My current code is shown below.
r = 20;
[X,Y,Z] = cylinder(r);
h = 80;
Z = Z*h;
figure(100)
s = surf(X,Y,Z,'FaceColor','#80B3FF', 'EdgeColor','none');
alpha(s,.2)
%axis([0 50 0 50 0 120])

采纳的回答

William Rose
William Rose 2022-12-2
r = 20;
p0=[25,25,0]; %base location
[X,Y,Z] = cylinder(r);
h = 80;
Z = Z*h;
X=X+p0(1); Y=Y+p0(2); Z=Z+p0(3); %translate cylinder to new location
figure(100)
s = surf(X,Y,Z,'FaceColor','#80B3FF', 'EdgeColor','none');
alpha(s,.2)
axis equal %show proportions correctly
Try it. Good luck.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by