Coordinates of graph nodes
4 次查看(过去 30 天)
显示 更早的评论
I've the following code
t = [1 1 1 1 2 2 3 4 4 5 6];
h = [2 3 4 5 3 6 6 5 7 7 7];
pos = [75 25; 115 45; 90 60; 10 5; 45 0; 45 55; 0 25]; % coordinates of nodes 1:7
g = graph(t,h);
plot(g, 'XData', pos(:,1), 'YData', pos(:,2));
where the coordinates of the initial set of nodes are specified to create the graph layout.
I want to add new nodes positioned between existing nodes. I don't have the coordinates of these new nodes.
For instance, I have deleted the existing edge between node 1 and 8 and added a new node and 2 new edges.
g = rmedge(g,1,2);
g = addedge(g,1,8);
g = addedge(g,8,2);
plot(g)
However, I am not sure how to specify the position of the new node. I want it to be positioned on the edge [1 2] , probably midway (Note: the exact position will vary depending on the number of nodes added in between node 1 and node 2. If two nodes are added, both has to be positioned along the straight line connecting edge [1 ---- 2])
Can some kind of a linear interpolation function be used to find the position of new node given the coordinates of end nodes (i.e given the coordinates of node 1 and 2 , I want the position of node 8 in betwen 1 and 2)? I'd like to keep this general. If n nodes have to be added , all n nodes should be placed equidistant.
Any suggestions on how to do this will be really helpful.
2 个评论
Mohammad Sami
2020-1-26
Please see the answer from John on how to find the coordinates of new nodes equally spaced between two existing nodes
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graph and Network Algorithms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!