2
$\begingroup$

I'm using the IGraph/M package to perform some calculations on graphs. Specifically, I want to use IGFaces to determine how many edges/vertices each face has for some calculations later down the line. What's going wrong is that the faces that it produces are not the ones I expect.I am able to reproduce this here:

g = Graph[
  Range[5],
  {1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3, 
   3 \[UndirectedEdge] 1, 2 \[UndirectedEdge] 4, 
   4 \[UndirectedEdge] 3, 3 \[UndirectedEdge] 5, 
   5 \[UndirectedEdge] 4}, 
  VertexCoordinates -> {{1.993577`, 27.381231`}, {2.920982`, 
     27.005762`}, {2.048629`, 26.343576`}, {2.96684`, 
     25.922899`}, {2.108422`, 25.318638`}}, 
VertexLabels -> "Name"]
IGFaces[g]

Output:

enter image description here

{{1, 2, 3}, {1, 3, 4, 2}, {2, 4, 5, 3}, {3, 5, 4}}

I do not expect these faces at all, I was expecting (and hoping) that I would get all the triangles you see there and big face that covers the "outer" edge, something like

{{1, 2, 3}, {2, 3, 4}, {3, 4, 5}, {1, 2, 4, 5, 3}}

I thought that by providing coordinates explicitly I would not have issues since it fixes the embedding. Any thoughts on what is going wrong?

Note that this graph is actually part of a bigger graph and the code is part of a bigger much messier code so it might be hard to provide additional details.

I'm using "IGraph/M 0.5.1 (October 12, 2020)" and Mathematica 12.3

$\endgroup$
2
  • $\begingroup$ PlanarFaceList is another alternative. Though for large graphs, IGFaces is much faster. $\endgroup$
    – Greg Hurst
    Jun 7, 2022 at 16:17
  • $\begingroup$ @GregHurst PlanarFaceList is part of Mathematica 13.0 (which I don't have) which is one of the main reasons I was using IGraph in the first place, but nonetheless a nice alternative. $\endgroup$ Jun 10, 2022 at 9:00

1 Answer 1

3
$\begingroup$

Ok I found the answer quite quickly after posting this. The function I needed was IGCoordinatesToEmbedding[]. This function gives an embedding which can be passed on to IGFaces[] and also IGDual[] (which I also need). Result:

IGFaces[IGCoordinatesToEmbedding[g]]

Output:

{{1, 3, 2}, {1, 2, 4, 5, 3}, {2, 3, 4}, {3, 5, 4}}
$\endgroup$
1
  • 1
    $\begingroup$ Yes, that's the answer. You can plot the graph using IGLayoutPlanar (which uses IGPlanarEmbedding and IGEmbeddingToCoordinates) to see where the faces that IGFaces gives by default come from. $\endgroup$
    – Szabolcs
    Jun 6, 2022 at 18:45

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.