Making Graph from Delaunay Triangulation
11 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I have made a graph from Delaunay triangulation. But the graph seemed to be aligned differently. Why it is so? If I have to add numbers to nodes of Delaunay how can I do that? Weights for the graph is the euclidean distance between two nodes. Attaching code and figure below.
DT = delaunayTriangulation(pts);
figure(2)
e=DT.edges;
pl=triplot(DT);
% Distances of the edges for weights
plist1 = pts(e(:,1),:);
plist2 = pts(e(:,2),:);
diffs = plist2-plist1;
if diffs<0
diffs=diffs*-1;
end
dists = vecnorm(diffs');
disp(dists);
% create Graph
G = graph(e(:,1), e(:,2), dists);
figure(3)
p = plot(G,'EdgeLabel',G.Edges.Weight);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/970740/image.png)
0 件のコメント
回答 (1 件)
Bruno Luong
2022 年 4 月 20 日
編集済み: Bruno Luong
2022 年 4 月 20 日
The plot of graph the graph is not supposed to respect the distance, only connectivity. Since it 's not always possible to project a graph to 2D screen while preserving the distance (weight). For example a graph the does not respect triangular inequality
G = graph([1 1 2],[2 3 3],[1 1 3]);
plot(G)
or a graph of a regular 3D tetrahedron
G=graph([1 1 1 2 2 3], [2 3 4 3 4 4], [1 1 1 1 1 1])
h=plot(G)
However you can set the coordinates as you like:
set(h,'XData',[sqrt(3)/3,-sqrt(3)/6,-sqrt(3)/6,0]);
set(h,'YData',[0,1/2,-1/2,0]);
set(h,'ZData',[0,0,0,sqrt(6)/3]);
axis equal
In your case it will be coordinates of pts
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Delaunay Triangulation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!