Plotting flux tubes on the surface of a sphere on matlab

363 Views Asked by At

I've been given the task to plot two flux tubes on a surface of a sphere, where one of the tubes twists around the other (to model magnetic helicity).

I know how to generate a sphere in Matlab, and how to generate a helical flux tube, but I'm a bit uncertain how to plot the flux tubes originating from a particular surface point on the sphere based on the scripts I currently have.

I have posted the scripts below and I'd be grateful if anyone could help me with this! I wasn't sure if this was a math or stackoverflow problem (or elsewhere) and so if it is and someone could redirect it that way, that'd also be great. Thanks!!

%% Set up vectors of parameters theta and phi.
Npoints = 27;
theta = linspace(0, pi, Npoints);
phi = linspace(0, 2*pi, Npoints);
%% Now create matrices of Cartesian values.
X = (sin(theta))'*cos(phi);
Y = (sin(theta))'*sin(phi);
Z = (cos(theta))'*ones(1, Npoints);
%% Choose colour: numbers between 0 and 1 for red, green, blue.
Gold = [.9,.8,.3]; Turquoise = [0.2,0.9,1];
%% draw the surface. Sometimes 'phong' works better than
% 'gouraud' for the texture. Set 'EdgeColor' to 'none' rather
% than 'black' to remove parameter lines.
surf(X,Y,Z,'facecolor', Turquoise, 'edgecolor','none',...
    'facelighting','gouraud')
%% Place a few lights. 
% First number: light position in phi direction (in degrees). 
% Second number: light position in theta direction.
camlight (-80, 45);
camlight (80, 25);
%% axis equal prevents distortion. axis off removes axes.
axis equal; axis on
title('Sphere', 'FontSize', 18)


%% Template for 3-Dimensional Curves. 
%% The range of the parameter t is set to 0 to 1.
Npoints = 100; Radius = 2; Height = 6; Coils = 6;
t = linspace(0,1,Npoints);
x = Radius*cos(Coils*2*pi*t);
y = Radius*sin(Coils*2*pi*t);
z = Height*t;
figure(1)
plot3(x,y,z, 'c', 'LineWidth',2.5)
title('Helix', 'FontSize', 14)
axis equal
1

There are 1 best solutions below

4
On

hm... what comes to my mind is a pretty dirty workaround idea using trisurf.

it is too long for the comments so i post it as answer, although i didnt try it:

The nodes: take a composed list of the nodes of the sphere and the nodes of the lines (eventually also containing the central points of each line segment for degenerate triangles, see below)

The triangulation: take the composed triangulation of the original triangulation of the sphere (you can get one by the delaunay function) and add the line segments as degenerate triangles (might well be that you should also use the central point on each line segments if a triangle with node indices (a,a,b) is rejected. eventually shift that central point by a veeeery tiny amount in a random direction (so the triangles would be almost-degenerate, to prevent they catch that as error))

you can also define a color vector for each triangle for trisurf.