How to plot streamlines on a sphere?

12 次查看(过去 30 天)
Bob P
Bob P 2013-1-9
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 CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by