Mentions légales du service

Skip to content
Snippets Groups Projects
Commit adb045d1 authored by DIB Elian's avatar DIB Elian
Browse files

Added function to compute triangular mesh from grid

parent 0e0091cb
Branches main
No related tags found
No related merge requests found
function varargout = triangulation(X,Y,varargin)
%TRIANGULATION Summary of this function goes here
% Detailed explanation goes here
p = inputParser();
p.addOptional('Z' , [] , @isnumeric);
p.addOptional('order', 'none', @ischar);
p.addOptional('fun' , @(x) min(x,[],2));
p.parse(varargin{:});
Z = p.Results.Z;
order = p.Results.order;
fun = p.Results.fun;
sz = size(X);
[X_,Y_] = ndgrid(1:(sz(1)-1),1:(sz(2)-1));
TX = reshape( (X_(:)+[0,1,0,1,0,1])' ,3,[])';
TY = reshape( (Y_(:)+[0,0,1,1,1,0])' ,3,[])';
T = sub2ind(sz,TX,TY);
switch order
case 'none'
I = (1:size(T,1))';
otherwise
Z_ = Z(T);
Z_ = fun(Z_);
[~,I] = sort(Z_,order);
T = T(I,:);
end
if nargout>0
varargout{1} = triangulation(T,X(:),Y(:));
end
if nargout>1
varargout{2} = I;
end
if nargout>2
varargout{3} = triangulation(T,X(:),Y(:),Z(:));
end
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment