How to plot a cylinder from a specified axis

121 Ansichten (letzte 30 Tage)
Telema Harry
Telema Harry am 2 Dez. 2022
Beantwortet: William Rose am 2 Dez. 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])

Akzeptierte Antwort

William Rose
William Rose am 2 Dez. 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.

Weitere Antworten (0)

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by