How can I graph the following parametric functions on a 3d graph?
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi everyone! The three functions are as follows:
- x=r*cos(theta)sin(phi)
- y=r*sin(theta)sin(phi)
- z=4r
the three equations should make a hemisphere. This is what I have:
theta=[0:0.1:6.28];
phi=[0:0.1:6.28];
r=[0:0.1:2];
[THETA,PHI]=meshgrid(theta,phi);
X2=R.*cos(THETA).*sin(PHI);
Y2=R.*sin(THETA).*sin(PHI);
Z2=R.*cos(PHI);
mesh(X2,Y2,Z2)
I know that's obviously not right, but I don't know what to do to make it right. Any help would be appreciated! Thanks!
0 Commenti
Risposte (2)
Marco Castelli
il 3 Dic 2014
If R is a constant the code is:
theta=[0:0.1:6.28];
phi=[0:0.1:6.28];
R=2;
[THETA,PHI]=meshgrid(theta,phi);
X2=R.*cos(THETA).*sin(PHI);
Y2=R.*sin(THETA).*sin(PHI);
Z2=R.*cos(PHI);
mesh(X2,Y2,Z2)
In this case , if you want to see how the surface changes with r, you can use subplot to plot more picture in one window:
theta=[0:0.1:6.28];
phi=[0:0.1:6.28];
R=1;
[THETA,PHI]=meshgrid(theta,phi);
X1=R.*cos(THETA).*sin(PHI);
Y1=R.*sin(THETA).*sin(PHI);
Z1=R.*cos(PHI);
R=2;
[THETA,PHI]=meshgrid(theta,phi);
X2=R.*cos(THETA).*sin(PHI);
Y2=R.*sin(THETA).*sin(PHI);
Z2=R.*cos(PHI);
mesh(X2,Y2,Z2)
figure
hold on
subplot(1,2,1)
mesh(X1,Y1,Z1)
axis([-2 2 -2 2 -2 2])
subplot(1,2,2)
mesh(X2,Y2,Z2)
axis([-2 2 -2 2 -2 2])
0 Commenti
Carlos Guerrero García
il 1 Dic 2022
And...what about an animation?
[THETA,PHI]=meshgrid(0:2*pi/60:2*pi,0:pi/60:pi);
for R=0.1:0.01:2;
mesh(R.*cos(THETA).*sin(PHI),R.*sin(THETA).*sin(PHI),R.*cos(PHI));
title(['R=',num2str(R)]);
axis equal;
axis([-2 2 -2 2 -2 2]);
drawnow;
end
0 Commenti
Vedere anche
Categorie
Scopri di più su Graphics Performance in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!