How to plot streamlines on a sphere?

3 ビュー (過去 30 日間)
Bob P
Bob P 2013 年 1 月 9 日
回答済み: David Taylor 2018 年 8 月 31 日
I would like to plot streamlines wrapped around the surface of a sphere. Here is what I mean:
A few thoughts:
--Matlab makes it easy to plot scalar functions on spheres using surf (as shown here: http://www.mathworks.com/help/matlab/ref/surf.html), but I do not see how to extend this example to vector fields.
--I know how to plot streamlines on a surface provided the domain of the surface is rectangular (following this example: http://www.mathworks.com/help/matlab/ref/streamslice.html). Unfortunately, I don't see how to extend this to a spherical surface.
Thanks!

回答 (2 件)

Bob P
Bob P 2013 年 1 月 9 日
Nevermind, I've figured out what I need. Something like this seems to work:
npts=100;
x = linspace(-1,1,npts);
y = linspace(-1,1,npts);
[X,Y]=meshgrid(x,y);
Z=X;
for r = 1:npts
for c = 1:npts
if (X(r,c)^2+Y(r,c)^2)>1
Z(r,c) = NaN;
else
Z(r,c)=sqrt(1-X(r,c)^2-Y(r,c)^2);
end
end
end
surf(X,Y,Z);shading interp
alpha(1)
[u v] = gradient(Z);
h = streamslice(X,Y,-u,-v);
set(h,'color','k')
for i=1:length(h);
zi = interp2(X,Y,Z,get(h(i),'xdata'),get(h(i),'ydata'));
set(h(i),'zdata',zi);
end
axis tight
%hold on;
%surf(X,Y,-Z);shading interp
%hold off;
daspect([1,1,1])
axis tight;

David Taylor
David Taylor 2018 年 8 月 31 日
Hero! Thanks for sharing.

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by