2
$\begingroup$

I have tried things like

With[{coords=Most@With[{n=23,\[Theta] = LambertW[1] }, 
N@(Table[{{Re[E^( I \[Theta])], -Im[E^( I \[Theta])]}, 
{Im[E^( I \[Theta])], Re[E^( I \[Theta])]}}.{Re[ E^(I  (1 + 2 \[Pi] ii/n))], 
Im[E^(I (1 + 2 \[Pi] ii/n))]}, {ii, Join[{n}, Range[n]]}])]},
Graph[{1 -> 3, 2 -> 7, 3 -> 6, 4 -> 5, 5 -> 11, 6 -> 10, 7 -> 9, 8 -> 17, 
9 -> 16, 10 -> 15, 11 -> 14, 12 -> 13, 13 -> 23, 14 -> 22, 15 -> 21, 
16 -> 20, 17 -> 19, 18 -> 7, 19 -> 6, 20 -> 5, 21 -> 4, 22 -> 3, 
23 -> 2, 8 -> 1, 12 -> 4, 13 -> 3, 14 -> 2, 15 -> 1}, 
DirectedEdges -> False, VertexLabels -> "Name", VertexCoordinates->coords ]]

which generates a graph with vertices out of order (I suppose coords must not be generated as I expected)

enter image description here

I have tried other things like GraphLayout -> {"CircularEmbedding"}, but that doesn't work either.

Have even tried

n=23;With[{coords=With[{polygon=Most@With[{\[Theta] = LambertW[1] }, 
N@(Table[{{Re[E^( I \[Theta])], -Im[E^( I \[Theta])]}, 
{Im[E^( I \[Theta])], Re[E^( I \[Theta])]}}.{Re[ E^(I  (1 + 2 \[Pi] ii/n))], 
Im[E^(I (1 + 2 \[Pi] ii/n))]}, {ii, Join[{n}, Range[n]]}])]},
With[{ points = N@RandomSample[Join[polygon, {{0, 0}}]]},
With[{ chm=ConvexHullMesh[points]},
With[{ ordering=MeshCells[chm,2][[1,1]]},
MeshCoordinates[chm][[ordering]]]]]]},
Graph[{1 -> 3, 2 -> 7, 3 -> 6, 4 -> 5, 5 -> 11, 6 -> 10, 7 -> 9, 8 -> 17, 
9 -> 16, 10 -> 15, 11 -> 14, 12 -> 13, 13 -> 23, 14 -> 22, 15 -> 21, 
16 -> 20, 17 -> 19, 18 -> 7, 19 -> 6, 20 -> 5, 21 -> 4, 22 -> 3, 
23 -> 2, 8 -> 1, 12 -> 4, 13 -> 3, 14 -> 2, 15 -> 1}, 
DirectedEdges -> False, VertexLabels -> "Name", VertexCoordinates->coords ]]

so I don't think its a problem with coords, but with graph order.

$\endgroup$
1

2 Answers 2

2
$\begingroup$

The vertex coordinates are applied to the vertexes in the order they are given, including the target nodes. Therefore 3 ends up before 2 and takes its position.

A way to correct your layout:

coords = Most@
   With[{n = 23, θ = LambertW[1]}, 
    N@(Table[{{Re[E^(I θ)], -Im[E^(I θ)]}, {Im[E^(I θ)], 
          Re[E^(I θ)]}}.{Re[E^(I (1 + 2 π ii/n))], 
         Im[E^(I (1 + 2 π ii/n))]}, {ii, Join[{n}, Range[n]]}])];

verts = {1 -> 3, 2 -> 7, 3 -> 6, 4 -> 5, 5 -> 11, 6 -> 10, 7 -> 9, 8 -> 17, 9 -> 16, 
   10 -> 15, 11 -> 14, 12 -> 13, 13 -> 23, 14 -> 22, 15 -> 21, 16 -> 20, 17 -> 19, 
   18 -> 7, 19 -> 6, 20 -> 5, 21 -> 4, 22 -> 3, 23 -> 2, 8 -> 1, 12 -> 4, 13 -> 3, 
   14 -> 2, 15 -> 1};

ord = DeleteDuplicates[Join @@ List @@@ verts];

Graph[verts, DirectedEdges -> False, VertexLabels -> "Name", 
 VertexCoordinates -> coords[[ord]]
]

enter image description here

In the words of the documentation:

enter image description here

Graph[verts] // VertexList
{1, 3, 2, 7, 6, 4, 5, 11, 10, 9, 8, 17, 16, 15, 14, 12, 13, 23, 22, 21, 20, 19, 18}
$\endgroup$
3
  • $\begingroup$ ah! I knew it was something I wasn't understanding! :) $\endgroup$
    – martin
    Commented Mar 13, 2015 at 9:06
  • 1
    $\begingroup$ @martin I added a documentation reference. $\endgroup$
    – Mr.Wizard
    Commented Mar 13, 2015 at 9:07
  • $\begingroup$ @martin Try: VertexCoordinates -> Reverse[coords][[ord]] $\endgroup$
    – Mr.Wizard
    Commented Mar 13, 2015 at 9:12
4
$\begingroup$

Just supply vertices when you define graph:

With[{coords = 
   Most@With[{n = 23, \[Theta] = LambertW[1]}, 
     N@(Table[{{Re[E^(I \[Theta])], -Im[E^(I \[Theta])]}, {Im[
            E^(I \[Theta])], Re[E^(I \[Theta])]}}.{Re[
           E^(I (1 + 2 \[Pi] ii/n))], 
          Im[E^(I (1 + 2 \[Pi] ii/n))]}, {ii, 
         Join[{n}, Range[n]]}])]}, 
 Graph[Range[23], {1 -> 3, 2 -> 7, 3 -> 6, 4 -> 5, 5 -> 11, 6 -> 10, 
   7 -> 9, 8 -> 17, 9 -> 16, 10 -> 15, 11 -> 14, 12 -> 13, 13 -> 23, 
   14 -> 22, 15 -> 21, 16 -> 20, 17 -> 19, 18 -> 7, 19 -> 6, 20 -> 5, 
   21 -> 4, 22 -> 3, 23 -> 2, 8 -> 1, 12 -> 4, 13 -> 3, 14 -> 2, 
   15 -> 1}, DirectedEdges -> False, VertexLabels -> "Name", 
  VertexCoordinates -> coords]]

enter image description here

$\endgroup$
1
  • $\begingroup$ so simple! Great! :) $\endgroup$
    – martin
    Commented Mar 13, 2015 at 16:18

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.