Using surf or equivalent with spherical coordinates
102 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'm working on a model which develops some surfaces in spherical coordinates which I would like to plot. But surf is designed for Cartesian coordinates and the dimensions don't work out correctly to simply do surf(sph2cart(theta, phi, r)).
Is there a nice simple way to get 3D plots in spherical coordinates? I was kind of hoping this would be straightforward since I'm just using it to visually check my model results.
0 comentarios
Respuestas (2)
Fangjun Jiang
el 5 de Nov. de 2011
Use function sph2cart() to calculate the data needed by surf().
Let's say you want to draw a sphere with radius of 10, Phi from -pi/3 to pi/3, Theta from 0 to pi. You can do the following.
R=10;
Phi=linspace(-pi/3,pi/3);
Theta=linspace(0,pi);
[Phi,Theta]=meshgrid(Phi,Theta);
[X,Y,Z]=sph2cart(Theta,Phi,R);
% Z=R*sin(Phi);
% X=R*cos(Phi).*cos(Theta);
% Y=R*cos(Phi).*sin(Theta);
surf(X,Y,Z);
2 comentarios
Fangjun Jiang
el 6 de Nov. de 2011
What is your spherical coordinates data? I am making something up in the answer.
Walter Roberson
el 5 de Nov. de 2011
No, there is no simple way to do 3D plots in spherical coordinates to display within any device which is inherently regularly-spaced cartesian coordinates. This is a mathematical issue, not a MATLAB problem.
To get the best approximation, you should first calculate the cartesian coordinates of each pixel to be rendered to, and back-project those to spherical coordinates, and do the function calculations at each of those spherical coordinates. This is the "pull" technique of rendering, whereas what you are using is the "push" technique (calculating destination coordinates from source coordinates), which is known to necessarily fail in some cases.
A problem, though, is that when you calculate the cartesian coordinates, you should take in to account the view projection from 3D to 2D that the rendering will necessarily undergo. Calculating proper source Z coordinates back from a flat image can be a bit tricky. And if you rotate the view, you need to recalculate destination and source locations and then recalculate the function values.
If this sounds like I am saying that you can either have accurate rendering or ease (and number of times) of function calculation, but not both, then Yes, that would be correct. "push" from spherical to cartesian will always give poor rendering, "pull" will require repeated recalculations as your view changes.
0 comentarios
Ver también
Categorías
Más información sobre Polar Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!