Draw a plane on a surface plot

조회 수: 12 (최근 30일)
Paul
Paul 2013년 3월 17일
답변: Satwik 2024년 12월 10일
Everything I try to do to draw a plane on a surface plot just keeps failing miserably. I just want to show the intersection! Can anyone help please?
I already have the surface plot coded: surfc(x,z,e);
x,z,e are all 21 x 17 matrix.
So I just tried doing this at the end:
for i = 1:length(x)
for j = 1:min(size(z))
p(i,j) = 0;
end
end
and the plots looked like this:
figure(15)
surfc(x,z,e);
set(gca,'ZScale','log');
hold on
surf(x,z,p);
But I can't see the plane...
I also tried making a mesh and doing it that way but then it said it can't plot negative numbers and so only plotted part of the mesh:
Any help?

답변 (1개)

Satwik
Satwik 2024년 12월 10일
Hi Paul,
To visualize the intersection of a plane with a surface plot, it is important to ensure that the plane is properly defined and positioned relative to the surface. Here are some steps to achieve this:
  1. Define the Plane Properly: Ensure the plane is defined correctly. For a plane at z = 0, the p matrix should have the same dimensions as e and be filled with zeros.
  2. Check Axes Limits: Make sure the axes limits allow the plane to be visible. Sometimes the plane might be outside the current view.
  3. Adjust Transparency: Use transparency to ensure both the surface and the plane are visible.
Here is a refined version of the code:
% Assuming x, z, e are already defined as 21 x 17 matrices
% Define the plane at z = 0
p = zeros(size(e));
% Plot the surface
figure(15);
surfc(x, z, e);
set(gca, 'ZScale', 'log');
hold on;
% Plot the plane
h = surf(x, z, p);
% Set the plane's color and transparency
set(h, 'FaceAlpha', 0.5, 'EdgeColor', 'none', 'FaceColor', [0 0 1]); % Blue, semi-transparent
% Adjust axes limits if necessary
zlim([-1, max(e(:))]); % Adjust based on your data range
% Add labels for clarity
xlabel('X-axis');
ylabel('Z-axis');
zlabel('E-axis');
title('Surface Plot with Intersection Plane');
% Hold off if you want to stop adding more plots
hold off;
I hope this helps!

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by