Using surf or equivalent with spherical coordinates
122 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Fangjun Jiang
2011-11-5
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 个评论
Fangjun Jiang
2011-11-6
What is your spherical coordinates data? I am making something up in the answer.
Walter Roberson
2011-11-5
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polar Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!