How to plot a cylinder from a specified axis

123 visualizzazioni (ultimi 30 giorni)
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])

Risposta accettata

William Rose
William Rose il 2 Dic 2022
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.

Più risposte (0)

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by