Draws a 3D hidden function iso-high line

조회 수: 1 (최근 30일)
跻 陈
跻 陈 2021년 9월 29일
답변: Vidhi Agarwal 2024년 12월 4일
I used the isosurface function to draw an image of the hidden function, and I wanted to show contours below the 3D graph.
The code is followed.
function sita45
[x,y,z]=meshgrid(linspace(0,0.04,300),linspace(0,0.5,300),linspace(0,0.2,200));
v=(3*log10(x)-182*x-15.079*y+2*log10(z)-48.912*z+15.62);
p=patch(isosurface(x,y,z,v,0));
view(3)
set(p, 'FaceColor', 'blue', 'Edgecolor', 'none');
camlight('headlight');lighting phong
Thank you for your help!

답변 (1개)

Vidhi Agarwal
Vidhi Agarwal 2024년 12월 4일
To enhance your 3D plot with contours below the graph in MATLAB, you can use the "contour" or "contourf" functions to add contour lines to the 2D projection on one of the coordinate planes.
Below is the modified code for the same:
function sita45
% Define the grid
[x, y, z] = meshgrid(linspace(0, 0.04, 300), linspace(0, 0.5, 300), linspace(0, 0.2, 200));
% Define the function values
v = (3*log10(x) - 182*x - 15.079*y + 2*log10(z) - 48.912*z + 15.62);
% Create the isosurface
p = patch(isosurface(x, y, z, v, 0));
set(p, 'FaceColor', 'blue', 'EdgeColor', 'none');
% Add lighting and view
camlight('headlight');
lighting phong;
view(3);
hold on;
% Add contours on the bottom plane (z = 0)
% Extract the slice at z = 0
[X, Y] = meshgrid(linspace(0, 0.04, 300), linspace(0, 0.5, 300));
% Use a small z value to avoid log(0)
V_slice = (3*log10(X) - 182*X - 15.079*Y + 2*log10(0.0001) - 48.912*0.0001 + 15.62);
% Plot contours
contour(X, Y, V_slice, 20, 'LineColor', 'black'); % Adjust the number of contour levels as needed
% Set axis labels
xlabel('X');
ylabel('Y');
zlabel('Z');
% Set other plot properties
axis tight;
grid on;
hold off;
end
For better understanding of "contour" or "contourf" refer to the following documentation:
Hope this helps!

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by