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

조회 수: 9 (최근 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