Hello
I have set of 2D points and after creation of voronoi polygons I want to calculeate distance between poit from one polygone and all neighborhood points (as in picture). Blue dots are my 2D points

 채택된 답변

Matt J
Matt J 2019년 6월 26일
편집: Matt J 2019년 6월 26일

1 개 추천

This returns the result as a distance matrix such as produced by pdist2, except that all entries not corresponding to neighboring points are set to NaN. Neighbors are defined as points whose Voronoi polygons share one or more (finite) vertices.
[V,C]=voronoin(points);
F=all(isfinite(V),2);
D=pdist2(points,points);
D(~common_vertex(C,F))=nan, %the result
function map = common_vertex(C,F)
n=numel(C);
map=false(n);
for i=1:n
for j=1:i-1
map(i,j)=any( F(intersect(C{i},C{j})) );
end
end
map=logical(map+map.');
map(1:n+1:end)=1;
end

댓글 수: 4

giometar
giometar 2019년 6월 27일
Thank you very much
This is exactly what I was looking for
I have to accelerate code because I have large number of points and operations with iterative procedure. So here is code with using adjacent matrix (hope that is correct way):
% Generate some coordinates
x=rand(20,1);
y=rand(20,1);
% Perform Delaunay triangulation
dt=delaunayTriangulation(x(:),y(:));
tri=dt.ConnectivityList;
NP=size(x,1); % Number of points
points=[x y];
% Calculate adjacency matrix (this part of code is taken from mr. Akira
% Agata
%https://www.mathworks.com/matlabcentral/answers/369143-how-to-do-delaunay-triangulation-and-return-an-adjacency-matrix
AdjMat = false(NP);
for kk = 1:size(tri,1)
AdjMat(tri(kk,1), tri(kk,2)) = true;
AdjMat(tri(kk,2), tri(kk,3)) = true;
AdjMat(tri(kk,3), tri(kk,1)) = true;
end
AdjMat = AdjMat | AdjMat';
% Calculate distance between all points
D=pdist2(points,points);
% Calculate distance between points conected with delaunay triangles
Distance=AdjMat.*D; % All values between points which are not connected with delaunay tri are zeros
Matt J
Matt J 2019년 7월 4일
편집: Matt J 2019년 7월 4일
hope that is correct way
Only you can know if it serves your needs, but I'm not sure it is equivalent to the neighborhood analysis you were originally pursuing. It assumes that points belonging to a common Delaunay triangle always occupy neighboring Voronoi poygons, and I'm not sure that's true.
giometar
giometar 2019년 7월 9일
that is the reason why I wrote "hope that is correct way"
I use both ways, to be sure that results are good :-)

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Voronoi Diagrams에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2019년 6월 26일

댓글:

2019년 7월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by