Code covered by the BSD License  

Highlights from
surfi

image thumbnail
from surfi by Ben Mitch
Plot (or return) surface interpolated from supplied vertices.

triangulate(varargin)
% v = triangulate(XYZ[, epsilon])
%
% where "XYZ" is a 3xN double matrix, with each column
% representing a vertex in three-dimensional space.
% triangulate will construct a list of triangles that
% together form a surface interpolating all of the supplied
% vertices. the output surface is of the form z=f(x,y).
%
% the triangle list is passed back as a list of indices into
% the vertex list. that is, "v" is a 3xM int32 array,
% with each column holding the indices of three columns of
% "XYZ". each triangle is specified clockwise (looking
% from above).
%
% "epsilon" is the tolerance to decide if a vertex falls on
% an existing edge; it defaults to eps - this is unlikely to
% be a sensible value if the vertex set has some regularity
% in it.
%
% NOTE: for correct operation the vertex list must be sorted
% correctly, by x coordinate first, then by y, then z.
% triangulate will do this if it is not already done, but it
% uses a simple sorting algorithm that may take some time.
% therefore, if you can sort the data more intelligently
% before passing in, performance may be improved.
%
% ported and extended from Paul Bourke's triangulate code at
% http://astronomy.swin.edu.au/~pbourke/terrain/triangulate/


% Compile stub



function varargout = triangulate(varargin)

if nargin && ischar(varargin{1}) && strcmp(varargin{1}, 'compile')
	
	c = pwd;
	
	try
		
		cd(fileparts(which('triangulate')));
		mex triangulate.cpp
		cd(c)
		disp('Compiled OK - next time you run "triangulate", the compiled MEX file will be run.');
		
	catch
		
		cd(c);
		
	end
	
else
	
	try
		c = fileparts(which('triangulate'));
	catch
		c = '<not found>';
	end
	
	% if this file runs, it is not yet compiled
	disp(' ')
	disp('****************************************************************')
	disp('****************************************************************')
	disp(' ')
	disp('triangulate has not been compiled yet; you must compile it before')
	disp('using surfi. try "triangulate compile", which may work. if it does')
	disp('not, switch to the install folder:')
	disp(' ')
	disp(c)
	disp(' ')
	disp('and run "mex triangulate.cpp".');
	disp(' ')
	error('must compile triangulate before using surfi');
	
end




Contact us at files@mathworks.com