- quiver: https://www.mathworks.com/help/matlab/ref/quiver.html?searchHighlight=quiver&s_tid=srchtitle_support_results_1_quiver
- imagesc:https://www.mathworks.com/help/matlab/ref/imagesc.html?searchHighlight=imagesc&s_tid=srchtitle_support_results_1_imagesc
projecting a 3D vector field onto a 2D plane
25 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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:
- k3 should give a colourmap for the plane, k3 increases monotonically from −1 to +1 as I move along Y.
- (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
0 Commenti
Risposte (1)
Jaswanth
il 24 Lug 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.
0 Commenti
Vedere anche
Categorie
Scopri di più su Vector Fields in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!