## How to plot streamlines on a sphere?

### Bob P (view profile)

on 9 Jan 2013
Latest activity Answered by David Taylor

### David Taylor (view profile)

on 31 Aug 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!

### Bob P (view profile)

on 9 Jan 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
alpha(1)
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;
%hold off;
daspect([1,1,1])
axis tight;