2D Projection of a 3D [f(x,y,z)] plot

38 vues (au cours des 30 derniers jours)
Naveen Pathak
Naveen Pathak le 28 Avr 2021
Modifié(e) : Naveen le 24 Juil 2024
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.

Réponses (2)

Jaswanth
Jaswanth le 24 Juil 2024
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.

Naveen
Naveen le 24 Juil 2024
Modifié(e) : Naveen le 24 Juil 2024
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.

Catégories

En savoir plus sur Contour Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by