필터 지우기
필터 지우기

Making Graph from Delaunay Triangulation

조회 수: 10 (최근 30일)
Aasha M V
Aasha M V 2022년 4월 20일
편집: Bruno Luong 2022년 4월 20일
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);

답변 (1개)

Bruno Luong
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])
G =
graph with properties: Edges: [6×2 table] Nodes: [4×0 table]
h=plot(G)
h =
GraphPlot with properties: NodeColor: [0 0.4470 0.7410] MarkerSize: 4 Marker: 'o' EdgeColor: [0 0.4470 0.7410] LineWidth: 0.5000 LineStyle: '-' NodeLabel: {'1' '2' '3' '4'} EdgeLabel: {} XData: [-1.1867 -0.7143 0.7143 1.1867] YData: [-0.7135 1.1881 -1.1881 0.7135] ZData: [0 0 0 0] Show all properties
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

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by