How to plot sphere in sphere coordinates?
Mostra commenti meno recenti
I'm just trying to plot known sphere coordinates:
function sphere(r)
phi = linspace(0,2*pi);
theta = linspace(0,pi);
x = r*cos(phi).*sin(theta);
y = r*sin(phi).*sin(theta);
z = r*cos(theta);
plot3(x,y,z)
end
However this isn't doing the trick. What have I mathematically confounded?
Risposta accettata
Più risposte (1)
Bruno Luong
il 21 Ott 2020
function sphere(r)
phi = linspace(0,2*pi);
theta = linspace(0,pi).'; % first change
x = r*cos(phi).*sin(theta);
y = r*sin(phi).*sin(theta);
z = r*cos(theta)+0*phi; % second change, make z same-size 2d array as x and y
plot3(x,y,z);
end
3 Commenti
J. Alex Lee
il 21 Ott 2020
nice. might be confusing depending on the audience though :)
As a side note, I wish plot also supported "implicit expansion" so you don't have to make the second change. As long as we have committed to the silent syntax, why not go the full nine yards!
Niklas Kurz
il 21 Ott 2020
Bruno Luong
il 21 Ott 2020
Click on .'
Categorie
Scopri di più su Surface and Mesh Plots in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!