How can I plot a skyrmion to sphere similar to the following picture

17 次查看(过去 30 天)
I'm a beginner in MATLAB, and I'm curious about how to plot 3D arrows mapped onto a sphere, similar to the image shown. I believe the problem can be divided into two steps: first, plotting arrows resembling a skyrmion, and then projecting them onto a sphere. Can you provide guidance on how to achieve this?
  2 个评论
Manikanta Aditya
Manikanta Aditya 2024-4-11
编辑:Manikanta Aditya 2024-4-11
Hi, Check this workaround which shows what you require:
% Define the number of arrows
n = 100;
% Generate spherical coordinates (theta and phi)
theta = linspace(0, pi, n);
phi = linspace(0, 2*pi, n);
[Theta, Phi] = meshgrid(theta, phi);
% Calculate 3D coordinates (x, y, z) from spherical coordinates
x = sin(Theta) .* cos(Phi);
y = sin(Theta) .* sin(Phi);
z = cos(Theta);
% Define the arrow vectors (u, v, w) based on the desired skyrmion-like pattern
u = -sin(Phi);
v = cos(Phi);
w = zeros(size(Theta));
% Scale the arrow vectors
scale = 0.3;
u = u * scale;
v = v * scale;
w = w * scale;
% Plot the sphere
[X, Y, Z] = sphere;
surf(X, Y, Z, 'FaceColor', 'texture', 'EdgeColor', 'none')
colormap bone
axis equal
hold on
% Plot the arrows on the sphere
quiver3(x, y, z, u, v, w, 'Color', 'r', 'LineWidth', 1)
hold off
If you found this helpful, let me know I will post it as answer, you can accept it.
玥
2024-4-11
Thank you very much for your response, it has been very helpful.
Building upon this, I'd like to inquire about how to make the color of the arrows vary gradually along the surface of the sphere. Could you please provide guidance on achieving this?

请先登录,再进行评论。

采纳的回答

Manikanta Aditya
Manikanta Aditya 2024-4-11
Hi,
To add to the earlier response, to know about making the color of the arrows vary gradually along the surface of the sphere. Check this functionationality of the code as per my understanding it should look this way:
% Define the number of arrows
n = 100;
% Generate spherical coordinates (theta and phi)
theta = linspace(0, pi, n);
phi = linspace(0, 2*pi, n);
[Theta, Phi] = meshgrid(theta, phi);
% Calculate 3D coordinates (x, y, z) from spherical coordinates
x = sin(Theta) .* cos(Phi);
y = sin(Theta) .* sin(Phi);
z = cos(Theta);
% Define the arrow vectors (u, v, w) based on the desired skyrmion-like pattern
u = -sin(Phi);
v = cos(Phi);
w = zeros(size(Theta));
% Scale the arrow vectors
scale = 0.3;
u = u * scale;
v = v * scale;
w = w * scale;
% Plot the sphere
[X, Y, Z] = sphere;
surf(X, Y, Z, 'FaceColor', 'texture', 'EdgeColor', 'none')
colormap bone
axis equal
hold on
% Plotting arrows with colors varying along Phi
colors = Phi; % or use another parameter that varies across your sphere
quiver3(x, y, z, u, v, w, 'Color', 'r', 'LineWidth', 1,'AutoScale','off');
hold off;

更多回答(0 个)

类别

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