projecting a 3D vector field onto a 2D plane

24 views (last 30 days)
KM
KM on 25 Feb 2023
Answered: Jaswanth on 24 Jul 2024
Hi,
I have a vector field (k= k1, k2, k3), these are spherical coordinates beasically, (). I have values as following:
theta = pi/2; and phi as a matrix here. ( also what if I have a phi as a function of x)
I want to plot k on 2D plane with following properties:
  1. k3 should give a colourmap for the plane, k3 increases monotonically from 1 to +1 as I move along Y.
  2. (k1, k2) has a constant direction should do a quiver plot on the plane. Along lines parallel to the x-axis, k3 is constant and hence the vector (k1, k2) has constant magnitude, but rotates through one revolution, being asymptotically vertical at both ends of the line.
what should be the idea or lines of code? plot shall be something like

Answers (1)

Jaswanth
Jaswanth on 24 Jul 2024
Hi,
To project a 3D vector field onto a 2D plane in MATLAB, you can follow a structured approach where ‘k3’ is represented as a colormap and ‘k1’, ‘k2’ form a quiver plot.
The grid can be defined over a range of ‘x’ and ‘y’ values. ‘k3’ is set as a function of ‘Y’, ranging from ‘-1’ to ‘1’, while ‘k1’ and ‘k2’ are derived from ‘phi’, which is a function of ‘X’ and ‘Y’. This ensures that the vectors follow the required direction and magnitude.
The imagesc function is used to plot ‘k3’ as a colormap, and the quiver function overlays the vector field (k1, k2) on the same plane, providing a clear visualization. Please adjust the definitions of ‘phi’, ‘k1’, and ‘k2’ based on your specific data and requirements.
Please refer to the following example code demonstrating the procedure discussed above:
% Define the grid
x = linspace(-pi, pi, 20); % X-axis from -pi to pi
y = linspace(-1, 1, 20); % Y-axis from -1 to 1
[X, Y] = meshgrid(x, y);
% Define k3 as a function of Y
k3 = Y;
% Define k1 and k2
theta = pi/2;
phi = atan2(Y, X); % This is just an example of phi as a function of X and Y
% k1 and k2 based on the given conditions
k1 = cos(phi);
k2 = sin(phi);
% Plot k3 as a colormap
figure;
imagesc(x, y, k3);
axis xy;
colorbar;
hold on;
% Plot the quiver plot for (k1, k2)
quiver(X, Y, k1, k2, 'k');
% Labels and title
xlabel('X-axis');
ylabel('Y-axis');
title('Projection of 3D Vector Field onto 2D Plane');
hold off;
Kindly refer to the following MathWorks documentation to know more about the functions discussed above:
I hope the information provided above is helpful.

Categories

Find more on Vector Fields in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!