Revolve a Plot around y axis to generate a 3D plot
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am interested in revolving a plot around the yaxis to generate a 3D plot.
Say,
theta =linspace(-pi/2,pi/2,100);
a=.75;
b=.25;
X=a*cos(theta);
Y=b*sin(theta)
Now I want to revolve that around the Y axis to generate a 3D plot. How would I do that without using the cylinder function?
I looked at some of the solutions on here, but I apply what they have I think its revolving around the x-axis instead of the y-axis.
0 Kommentare
Antworten (2)
Dyuman Joshi
am 17 Nov. 2023
%2D Data
n = 100;
theta = linspace(-pi/2,pi/2,n);
a=.75;
b=.25;
X=a*cos(theta);
Y=b*sin(theta);
%plot the 2D curve
figure
plot(X, Y)
xlabel x
ylabel y
%% Generate data for x and z, as revolution is around y-axis
t0 = linspace(0, 2*pi, n).';
x = X.*cos(t0);
z = X.*sin(t0);
%repeat the same data for y
y = repmat(Y, n, 1);
%plot the surface
figure
surf(x, y, z)
xlabel x
ylabel y
zlabel z
%% Change the view to x-y plane to check
figure
surf(x, y, z)
xlabel x
ylabel y
zlabel z
view([0 0 1])
4 Kommentare
Dyuman Joshi
am 17 Nov. 2023
@Torsten, Thanks.
@Kenneth, here is the modified result -
%2D Data
n = 100;
theta = linspace(-pi/2,pi/2,n);
a=.75;
b=.25;
X=a*cos(theta);
Y=b*sin(theta);
%plot the 2D curve
figure
plot(X, Y)
xlabel x
ylabel y
%% Generate data for x and z, as revolution is around y-axis
t0 = linspace(0, 2*pi, n).';
x = X.*cos(t0);
z = X.*sin(t0);
%repeat the same data for y
y = repmat(Y, n, 1);
%plot the surface
figure
surf(x, y, z)
xlabel x
ylabel y
zlabel z
axis equal
%% Change the view to x-y plane to check
figure
surf(x, y, z)
xlabel x
ylabel y
zlabel z
view([0 0 1])
axis equal
Star Strider
am 17 Nov. 2023
Try this —
theta =linspace(-pi/2,pi/2,100);
a=.75;
b=.25;
X=a*cos(theta);
Y=b*sin(theta);
figure
plot(X, Y)
grid
xlabel('X')
ylabel('Y')
zlabel('Z')
axis('equal')
title('Elevation Profile')
[Xs,Ys,Zs] = sphere(50);
Xs = Xs*a;
Ys = Ys*a;
Zs = Zs*b;
figure
hs = surf(Xs, Ys, Zs);
xlabel('X')
ylabel('Y')
zlabel('Z')
axis('equal')
colormap(turbo)
% rotate(hs, [1 0 0], 90)
figure
hs = surf(Xs, Ys, Zs);
xlabel('X')
ylabel('Y')
zlabel('Z')
axis('equal')
colormap(turbo)
view(0,90)
title('Top View')
figure
hs = surf(Xs, Ys, Zs);
xlabel('X')
ylabel('Y')
zlabel('Z')
axis('equal')
colormap(turbo)
view(90,0)
title('Side View')
Make appropriate changes to get the result you want.
.
3 Kommentare
Star Strider
am 17 Nov. 2023
The sphere function has been stable for as long as I’ve been using it, literally decades. (There is no absolute guarantee that all code is going to be compatible with all future MATLAB releases, regardless.) With respect to evolving over time, that requires updating the variable multiplications:
[Xs,Ys,Zs] = sphere(50);
Xs = Xs*a;
Ys = Ys*a;
Zs = Zs*b;
with each update of ‘a’ and ‘b’.
If you want to animate it, that means either re-drawing it each time and displaying them, or storing all the updates in a matrix (most likely a cell array) and then looping through the matrix to display them. See the documentation section on Animation for those details.
.
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!









