How can I generate a plane surface in MATLAB?

조회 수: 212 (최근 30일)
MathWorks Support Team
MathWorks Support Team 2009년 6월 27일
댓글: Sam Chak 2025년 4월 29일
How can I generate a plane surface in MATLAB?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2020년 11월 5일
편집: MathWorks Support Team 2020년 11월 5일
The following are some examples of how the xy-plane can be plotted in MATLAB. A generalized example, showing how to plot any arbitrary plane, follows.
PLOTTING THE XY-PLANE
=====================
The following shows two methods for constructing an xy-plane, bounded at (1,1,0), (-1,1,0), (-1,-1,0), and (1,-1,0).
Method 1: The PATCH Function
You can draw a polygonal graphics object by using the PATCH function and specifying its vertices. By specifying four corners, you can construct the xy-plane as follows:
% Use fourth input for color scale.
patch([1 -1 -1 1], [1 1 -1 -1], [0 0 0 0], [1 1 -1 -1])
Method 2: The MESHGRID and SURF functions.
Using the MESHGRID function, you can generate data points for the xy-plane. Afterwards, use the SURF function to generate the surface plot.
[x y] = meshgrid(-1:0.1:1); % Generate x and y data
z = zeros(size(x, 1)); % Generate z data
surf(x, y, z) % Plot the surface
Note that by making some simple changes to the above examples, the xz- and yz-planes can be plotted. For example, to plot the xz-plane use:
patch( [1 -1 -1 1] , [0 0 0 0], [1 1 -1 -1], [1 1 -1 -1])
For more information on the PATCH function, see the following URL:
PLOTTING AN ARBITRARY PLANE
===========================
The following shows two methods for constructing, an arbitrary plane of the form:
Ax + By + Cz + D = 0,
where the coefficients "A", "B", "C", and "D" are known values.
Method 1: The PATCH Function
x = [1 -1 -1 1]; % Generate data for x vertices
y = [1 1 -1 -1]; % Generate data for y vertices
z = -1/C*(A*x + B*y + D); % Solve for z vertices data
patch(x, y, z);
Method 2: The MESHGRID and SURF Functions.
[x y] = meshgrid(-1:0.1:1); % Generate x and y data
z = -1/C*(A*x + B*y + D); % Solve for z data
surf(x,y,z) %Plot the surface
For more information on the MESHGRID and SURF functions, see the following URLs:
https://www.mathworks.com/help/matlab/ref/meshgrid.html

추가 답변 (1개)

xingxingcui
xingxingcui 2025년 3월 29일
For R2024b or later ,please use constantplane function.
  댓글 수: 2
John D'Errico
John D'Errico 2025년 4월 29일
I never noticed this function appear. It was probably my feature request that caused it to happen, as a few years back, I asked for exactly this capability in MATLAB. I really should check the release notes more often.
Sam Chak
Sam Chak 2025년 4월 29일
Thank you for promoting this function. It operates similarly to xline and yline, but for 3D.
[X, Y] = meshgrid(-1:0.05:1);
Z = exp(- 5*(X.^2 + Y.^2));
mesh(X,Y,Z)
xlabel('x'), ylabel('y'), zlabel('z')
zlim([0, 1.5])
cp = constantplane("x", 0, FaceAlpha=0.5);

댓글을 달려면 로그인하십시오.

카테고리

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

제품


릴리스

R13SP1

Community Treasure Hunt

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

Start Hunting!

Translated by