# Link closest points accross altitudes in Matlab, problem with Delaunay Triangulation/ Nearest neighbor finding

조회 수: 1 (최근 30일)
Paul C 2014년 11월 10일
편집: Paul C 2014년 11월 10일
I have a 3d matrix with scattered points (Nx4 matrix, x-y-z-data). My aim is to link the closest points together and register each chain in an Kx4 array (x, y, z, data), K being the chain length. The total number of chains depends on the points... A particularity is that these lines only go upwards (z+), I don't want to link points on same z, or go down.
I have been trying different strategies so far, one being with another array shape (Mx4xNz - basically meaning the values were stacked per z's instead of being all on a 2d matrix):
1. pick a point at level Zn
2. go to level Zn+1, look for the closest point in a range of coordinates x,y using delaunayTriangulation and nearestNeighbor
3. register the point into a vector
(I suspect there are other possibilities using nearestNeighbor with the Nx4 matrix, but i can't think how to 'direct' the search upwards and chain the successive points... )
I find myself with the following problem : The finding of nearest point upwards seems to work well but in 1 horizontal direction only!!
Anyone has an idea as to why this is happens? I suspect the problem might be with assigning correctly the nearest neighbor found, but I don't see how the extraction I did in my code below would be wrong?? Thanks for any help!!
Note - During the loop I have the warning : Duplicate data points have been detected and removed. The Triangulation indices are defined with respect to the unique set of points in delaunayTriangulation property X.
Lign=zeros(max_iter,4,s);
for i = 1:s;
pp_id=i;
for n=1:max_iter-1;
Wn=W(:,:,n); % W is the data 3d-matrix Mx4xNz, as attached
Wnn=W(:,:,n+1);
Point_n = Wn(pp_id,:);
xn= Point_n(1);
yn= Point_n(2);
zn= Point_n(3);
vn= Point_n(4);
if xn==0|yn==0|zn==0|vn==0;
break
end
% Look for nearest neighbour at next level
DT=delaunayTriangulation(Wnn(:,[1:2]));
[pp_id, d]=nearestNeighbor(DT,[xn,yn]);
% limit range
if d>10
break
end
% extraction of values at row pp_id
Point_n=Wnn(pp_id,:);
% register point in line
Lign(n,:,i)=Point_n;
end
end
figure;
clf;
hold on;
plot3(W(:,1),W(:,2),W(:,3),r*','markersize',2,'linewidth',1);
for i=1:s
plot3(Lign(:,1,i),Lign(:,2,i),Lign(:,3,i),'k','linewidth',1);
end

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Spatial Search에 대해 자세히 알아보기

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by