Filter löschen
Filter löschen

Making Graph from Delaunay Triangulation

10 Ansichten (letzte 30 Tage)
Aasha M V
Aasha M V am 20 Apr. 2022
Bearbeitet: Bruno Luong am 20 Apr. 2022
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);

Antworten (1)

Bruno Luong
Bruno Luong am 20 Apr. 2022
Bearbeitet: Bruno Luong am 20 Apr. 2022
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

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by