- 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
조회 수: 16 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Jaswanth
2024년 7월 24일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Vector Fields에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!