How can I generate a plane surface in MATLAB?
218 ビュー (過去 30 日間)
古いコメントを表示
採用された回答
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
0 件のコメント
その他の回答 (1 件)
xingxingcui
2025 年 3 月 29 日
2 件のコメント
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
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 Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!