How can I generate a plane surface in MATLAB?
972 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Jun 2009
Edited: MathWorks Support Team
on 5 Nov 2020
How can I generate a plane surface in MATLAB?
Accepted Answer
MathWorks Support Team
on 5 Nov 2020
Edited: MathWorks Support Team
on 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 Comments
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!