- contourf: https://www.mathworks.com/help/matlab/ref/contourf.html?searchHighlight=contourf&s_tid=srchtitle_support_results_1_contourf#d126e250644
- view(2): https://www.mathworks.com/help/matlab/ref/view.html?searchHighlight=view&s_tid=srchtitle_support_results_1_view#d126e1827914:~:text=view(90%2C0)-,Display%20Surface%20in%20a%202%2DD%20View,-Change%20the%20View
2D Projection of a 3D [f(x,y,z)] plot
42 ビュー (過去 30 日間)
古いコメントを表示
Greetings.
Please, can someone help me to learn how I can make the 2D projection of a 3D figure as shown in the attached figure.
Thank you.
0 件のコメント
回答 (2 件)
Jaswanth
2024 年 7 月 24 日
Hi Naveen,
To create a 2D projection of a 3D plot defined by a function (f(x, y, z)) in MATLAB, use the contourf function, which provides a filled contour plot, making the 2D representation clearer. Create three subplots for the XY, YZ, and XZ planes. For each subplot, use contourf with the appropriate coordinates. Set the view to 2D using view(2) to ensure the plot is displayed correctly.
Please refer to the following example code demonstrating the above discussed steps:
% Define the fluted sphere function
theta = linspace(0, 2*pi, 100);
phi = linspace(0, pi, 50);
[theta, phi] = meshgrid(theta, phi);
% Fluted sphere parameters
a = 1; % Radius
b = 0.2; % Amplitude of fluting
% Parametric equations for the fluted sphere
x = (a + b * cos(5*theta)) .* sin(phi) .* cos(theta);
y = (a + b * cos(5*theta)) .* sin(phi) .* sin(theta);
z = (a + b * cos(5*theta)) .* cos(phi);
% Create a figure
figure;
% Plot the 3D fluted sphere in the first subplot
subplot(2, 2, 1);
surf(x, y, z);
colorbar;
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('3D Fluted Sphere');
view(3); % Default 3D view
shading interp; % Improve visualization
% Plot the 2D projection on the XY plane in the second subplot
subplot(2, 2, 2);
contourf(x, y, z, 20); % Using contourf for better 2D visualization
colorbar;
xlabel('X-axis');
ylabel('Y-axis');
title('2D Projection on XY Plane');
view(2); % 2D view
% Plot the 2D projection on the YZ plane in the third subplot
subplot(2, 2, 3);
contourf(y, z, x, 20); % Using contourf for better 2D visualization
colorbar;
xlabel('Y-axis');
ylabel('Z-axis');
title('2D Projection on YZ Plane');
view(2); % 2D view
% Plot the 2D projection on the XZ plane in the fourth subplot
subplot(2, 2, 4);
contourf(x, z, y, 20); % Using contourf for better 2D visualization
colorbar;
xlabel('X-axis');
ylabel('Z-axis');
title('2D Projection on XZ Plane');
view(2); % 2D view
% Optionally, you can adjust the colormap
colormap jet;
Kindly refer to the following MathWorks documentation to know more about the functions discussed above:
I hope the information provided above is helpful.
0 件のコメント
Naveen
2024 年 7 月 24 日
編集済み: Naveen
2024 年 7 月 24 日
Hi Jaswant,
Thank you for providing an elegant way of doing this, I apprecitate your help.
I solved this problem by taking a 2D projection from any plane (usually ceter) and moved it to the bottom of the figure along each axis. This way I can make (in a single figure) both 3D and its 2D projection along each wall of the figure.
Thanks again.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Contour Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!