I have a set of data that are sampled from the outer walls of a spherical object. I would like to create a 3D object that I can rotate and translate.
MATLAB: How to create a 3D surface with points of data in MATLAB 6.5 (R13)
3-ddataMATLABmodelpointsshellskinsurface
Related Solutions
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 dataz = -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
The function SURF expects a neat rectilinear grid to be supplied to it before it can render the surface. It is not possible to use this function directly to render a surface with unordered coordinates.
As a workaround the function TRISURF can be used to create the surface in conjunction with the DELAUNAY function. The DELAUNAY function performs the triangulation and returns a mx3 matrix "Tri" which defines each triangle used to render the surface. Each row of "Tri" defines a single triangular face by indexing into the vectors or matrices that contain the X, Y, and Z vertices. This "Tri" matrix can then be used with TRISURF to generate the surface.
The following code illustrates the use of DELAUNAY and TRISURF to generate a surface:
load seamount;tri = delaunay(x,y);h = trisurf(tri, x, y, z);axis offl = light('Position',[-50 -15 29])set(gca,'CameraPosition',[208 -50 7687])lighting phongshading interpcolorbar EastOutsideaxis vis3d
Best Answer