Mentions légales du service

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

Fixed missing triangle intersections when using pointLocation

due to floating point errors.
The intersections are evaluated after shifting the reference and query values by the same offset in different directions which reduces the number of errors.
parent e43c5e92
Branches
No related tags found
No related merge requests found
...@@ -2,10 +2,34 @@ function [Xq,Yq,X,Y,varargout] = gridCoords(X,Y,Xq,Yq,varargin) ...@@ -2,10 +2,34 @@ function [Xq,Yq,X,Y,varargout] = gridCoords(X,Y,Xq,Yq,varargin)
%GRIDCOORDS Summary of this function goes here %GRIDCOORDS Summary of this function goes here
% Detailed explanation goes here % Detailed explanation goes here
I = (1:numel(X))';
offset = 1e-2;
p = inputParser();
p.addOptional('I' , I , @isnumeric);
p.addOptional('offset', offset, @isnumeric);
p.parse(varargin{:});
I = p.Results.I;
offset = p.Results.offset;
sz = size(Xq); sz = size(Xq);
[t,I] = utils.triangulation(X,Y,varargin{:}); ind = nan(numel(Xq),1);
[ind,b] = t.pointLocation(Xq(:),Yq(:)); b = nan(numel(Xq),3);
nanmask = true(numel(Xq),1);
[dX,dY] = ndgrid([-offset,0,offset]);
sigma = [5,4,6,2,8,1,3,7,9];
for r = 1:numel(sigma)
dx = dX(sigma(r));
dy = dY(sigma(r));
t = utils.triangulation(X+dx,Y+dy,I);
[ind(nanmask),b(nanmask,:)] = t.pointLocation(Xq(nanmask)+dx,Yq(nanmask)+dy);
nanmask = isnan(ind);
end
ind = reshape(ind,sz); ind = reshape(ind,sz);
u = reshape(b(:,2),sz); u = reshape(b(:,2),sz);
...@@ -13,7 +37,6 @@ v = reshape(b(:,3),sz); ...@@ -13,7 +37,6 @@ v = reshape(b(:,3),sz);
nanind = isnan(ind); nanind = isnan(ind);
ind(nanind) = 1; ind(nanind) = 1;
ind = I(ind);
ut = ~mod(ind,2); ut = ~mod(ind,2);
ind(nanind) = nan; ind(nanind) = nan;
......
function varargout = triangulation(X,Y,varargin) function t = triangulation(X,Y,varargin)
%TRIANGULATION Summary of this function goes here %TRIANGULATION Summary of this function goes here
% Detailed explanation goes here % Detailed explanation goes here
I = (1:numel(X))';
p = inputParser(); p = inputParser();
p.addOptional('Z' , [] , @isnumeric); p.addOptional('I', I, @isnumeric);
p.addOptional('order', 'none', @ischar);
p.addOptional('fun' , @(x) min(x,[],2));
p.parse(varargin{:}); p.parse(varargin{:});
Z = p.Results.Z; I = p.Results.I;
order = p.Results.order;
fun = p.Results.fun;
sz = size(X); sz = size(X);
...@@ -20,26 +17,8 @@ TY = reshape( (Y_(:)+[0,0,1,1,1,0])' ,3,[])'; ...@@ -20,26 +17,8 @@ TY = reshape( (Y_(:)+[0,0,1,1,1,0])' ,3,[])';
T = sub2ind(sz,TX,TY); T = sub2ind(sz,TX,TY);
switch order Ii(I) = 1:numel(I);
case 'none'
I = (1:size(T,1))'; t = triangulation(Ii(T),X(I(:)),Y(I(:)));
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 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