How to plot a cylinder from a specified axis

118 visualizaciones (últimos 30 días)
Telema Harry
Telema Harry el 2 de Dic. de 2022
Respondida: William Rose el 2 de Dic. de 2022
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])

Respuesta aceptada

William Rose
William Rose el 2 de Dic. de 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.

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by