How to plot streamlines on a sphere?

11 visualizaciones (últimos 30 días)
Bob P
Bob P el 9 de En. de 2013
Respondida: David Taylor el 31 de Ag. de 2018
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!

Respuestas (2)

Bob P
Bob P el 9 de En. de 2013
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 el 31 de Ag. de 2018
Hero! Thanks for sharing.

Categorías

Más información sobre Surface and Mesh 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!

Translated by