www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/UsingTheDelaunayAndDelaunaynFunctionsExample.m

    %% Using the delaunay and delaunayn functions

% Copyright 2015 The MathWorks, Inc.


%% Section 1
% This example shows how to use the |delaunay| function to create a 2-D
% Delaunay triangulation from the seamount data set. A _seamount_ is an
% underwater mountain. The data set consists of a set of longitude (|x|)
% and latitude (|y|) locations, and corresponding seamount elevations (|z|)
% measured at those coordinates.

%%
% Load the seamount data set and view the (|x|, |y|) data as a scatter
% plot.
load seamount
plot(x,y,'.','markersize',12)
xlabel('Longitude'), ylabel('Latitude')
grid on

%%
% Construct a Delaunay triangulation from this point set and use |triplot|
% to plot the triangulation in the existing figure.
tri = delaunay(x,y);
hold on, triplot(tri,x,y), hold off

%%
% Add the depth data (|z|) from seamount to lift the vertices and create
% the surface.  Create a new figure and use |trimesh| to plot the surface
% in wireframe mode.
figure
hidden on
trimesh(tri,x,y,z)
xlabel('Longitude'),ylabel('Latitude'),zlabel('Depth in Feet');

%%
% If you want to plot the surface in shaded mode, use |trisurf| instead of
% |trimesh|.

%%
% A 3-D Delaunay triangulation also can be created using the |delaunay|
% function. This triangulation is composed of tetrahedra.

%% Section 2
% This example shows how to create a 3-D Delaunay triangulation of a random
% data set. The triangulation is plotted using |tetramesh|, and the
% |FaceAlpha| option adds transparency to the plot.
X = gallery('uniformdata',[30 3],0);
tet = delaunay(X);
faceColor  = [0.6875 0.8750 0.8984];
tetramesh(tet,X,'FaceColor', faceColor,'FaceAlpha',0.3);