2
$\begingroup$

Suppose we have the given network 'g1', which we get based on the set 'q1':

q1 = {{6545, 1044}, {6546, 1044}, {6536, 1044}, {6537, 1043}, {6529, 1044}, {6530, 1043}, {6528, 1044}, {6529, 1044}, {6528, 1044}, {6529, 1043}, {6527, 1044}, {6528, 1044}, {6522,1044}, {6523, 1043}, {6544, 1045}, {6545, 1044}, {6535,1045}, {6536, 1044}, {6526, 1045}, {6527, 1044}, {6521,1045}, {6522, 1044}, {6543, 1046}, {6544, 1045}, {6534,1046}, {6535, 1045}, {6525, 1046}, {6526, 1045}, {6521, 1046}, {6522, 1045}, {6520, 1046}, {6521, 1045}, {6517, 1046}, {6518, 1047}, {6542, 1047}, {6543, 1048}, {6542, 1047}, {6543, 1046}, {6535, 1047}, {6536, 1046}, {6534,1047}, {6535, 1047}, {6533, 1047}, {6534, 1047}, {6533, 1047}, {6534, 1046}, {6532, 1047}, {6533, 1047}, {6531, 1047}, {6532, 1047}, {6525, 1047}, {6526, 1048}, {6524, 1047}, {6525, 1047}, {6524, 1047}, {6525, 1046}, {6520, 1047}, {6521, 1046}, {6519, 1047}, {6520, 1047}, {6519, 1047}, {6520, 1046}, {6518, 1047}, {6519, 1047}, {6518, 1047}, {6518, 1048}, {6549, 1048}, {6550, 1049}, {6543, 1048}, {6544, 1049}, {6532, 1048}, {6533, 1049}, {6532, 1048}, {6533, 1047}, {6530, 1048}, {6531, 1047}, {6526, 1048}, {6527, 1049}, {6523, 1048}, {6524, 1047}, {6518, 1048}, {6518, 1049}, {6550, 1049}, {6551, 1050}, {6548, 1049}, {6549, 1048}, {6547, 1049}, {6548, 1049}, {6545, 1049}, {6546, 1050}, {6544, 1049}, {6545, 1049}, {6543, 1049}, {6544, 1049}, {6542, 1049}, {6543, 1049}, {6539, 1049}, {6540, 1050}, {6538, 1049}, {6539, 1049}, {6537, 1049}, {6538, 1049}, {6536, 1049}, {6537, 1049}, {6533, 1049}, {6534, 1050}, {6529, 1049}, {6530, 1048}, {6529, 1049}, {6529, 1050}, {6527, 1049}, {6528, 1050}, {6522, 1049}, {6523, 1048}, {6518, 1049}, {6519, 1050}, {6518, 1049}, {6518, 1050}, {6551, 1050}, {6551, 1051}, {6546, 1050}, {6547, 1049}, {6543, 1050}, {6544, 1049}, {6541, 1050}, {6542, 1049}, {6540, 1050}, {6541, 1050}, {6535, 1050}, {6536, 1049}, {6534, 1050}, {6535, 1050}, {6529, 1050}, {6529, 1051}, {6528, 1050}, {6529, 1051}, {6521, 1050}, {6522, 1049}, {6519, 1050}, {6520, 1051}, {6551, 1051}, {6551, 1052}, {6542, 1051}, {6543, 1050}, {6529, 1051}, {6529, 1052}, {6520, 1051}, {6521, 1052}, {6520, 1051}, {6521, 1050}, {6517, 1051}, {6518, 1050}, {6551, 1052}, {6552, 1052}, {6541, 1052}, {6542, 1051}, {6529,1052}, {6530, 1053}, {6521, 1052}, {6522, 1053}, {6540, 1053}, {6541, 1052}, {6538, 1053}, {6539, 1054}, {6531,1053}, {6532, 1054}, {6530, 1053}, {6531, 1054}, {6530, 1053}, {6531, 1053}, {6522, 1053}, {6522, 1054}, {6539, 1054}, {6540, 1053}, {6531, 1054}, {6532, 1055}, {6533, 1055}, {6534, 1054}, {6532, 1055}, {6533, 1056}, {6532, 1055}, {6533, 1055}, {6521, 1055}, {6522, 1054}, {6533, 1056}, {6533, 1057}, {6520, 1056}, {6521, 1055}, {6534, 1057}, {6535, 1056}, {6533, 1057}, {6534, 1057}, {6519, 1057}, {6520, 1056}, {6518, 1058}, {6519, 1057}, {6517, 1059}, {6518, 1058}};
linesObjects = Map[Line@# &, Partition[q1, 2]];
g1 = Graphics[linesObjects, ImageSize -> 500]

enter image description here

Then we build the graph 'graph':

points = DeleteDuplicates[q1];
pointIndex = First /@ PositionIndex[points];
vertexCoordinates = AssociationMap[Reverse, pointIndex];
edges = BlockMap[Apply[UndirectedEdge], pointIndex /@ q1, 2];
graph = Graph[edges, VertexCoordinates -> Normal@vertexCoordinates]

enter image description here

Question: how to determine the set 'q1' from the 'graph' so as to reproduce the 'g1' network?

Example: Let 'graph1' be:

vtx[] := Table[i <-> RandomInteger[{0, i - 1}], {i, 1, 200}];
graph1 = Graph[vtx[], GraphLayout -> "SpringEmbedding"]

How to get the set 'q2' (analogous to the set 'q1') from the graph 'graph1' so as to get the network 'g2' (analogous to the network 'g1')?

$\endgroup$

1 Answer 1

4
$\begingroup$

Are you looking to convert a graph into a graphics and get the lines representing all the edges? If so:

lines = Cases[Normal@Show[graph1], _Line, Infinity];
Graphics[lines]

creates and displays the lines. Note the use of Normal to convert from a GraphicsComplex to lines with the actual coordinates.

Or are you looking for the vertex coordinates for the endpoints of each edge?

For that, start with the coordinates of each vertex: (in version 12.1, use AnnotationValue instead of PropertyValue)

coords = Association[(# -> 
   PropertyValue[{graph1, #}, VertexCoordinates]) & /@ 
VertexList[graph1]];

then get the coordinates of the ends of each edge:

edgeCoordinates = Table[{coords[e[[1]]], coords[e[[2]]]}, {e, EdgeList[graph1]}];

Make a graph of lines of these edges

Graphics[Line /@ edgeCoordinates]

or for all segments in a single Line

Graphics[Line[edgeCoordinates]]
$\endgroup$
1
  • $\begingroup$ This is it! Thanks! $\endgroup$
    – ralph
    May 5, 2020 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.