How to plot a cylinder from a specified axis
87 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Telema Harry
le 2 Déc 2022
Réponse apportée : William Rose
le 2 Déc 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])
0 commentaires
Réponse acceptée
William Rose
le 2 Déc 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.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!