How can I generate a plane surface in MATLAB?
223 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 27 Jun. 2009
Kommentiert: Sam Chak
am 29 Apr. 2025
How can I generate a plane surface in MATLAB?
Akzeptierte Antwort
MathWorks Support Team
am 5 Nov. 2020
Bearbeitet: MathWorks Support Team
am 5 Nov. 2020
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 Kommentare
Weitere Antworten (1)
xingxingcui
am 29 Mär. 2025
2 Kommentare
John D'Errico
am 29 Apr. 2025
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
am 29 Apr. 2025
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);
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
