planar_faces

Contents

planar_faces#

graph_tool.structure.planar_faces(g, edges=False)[git][source]#

Return the faces of a planar embedding of the graph.

Parameters:
gGraph

Graph to be used (the edge directions are ignored).

edgesbool (optional, default: False)

If True, the faces are returned as sequences of edge indices instead of vertices.

Returns:
faceslist of numpy.ndarray or None

The vertices (or edges) around every face, in cyclic order, or None if the graph is not planar.

See also

is_planar

Planarity test and embedding

graph_tool.generation.make_maximal_planar

Maximal planar supergraph

graph_tool.draw.planar_layout

Straight-line planar drawing

Notes

A planar embedding is found with the Boyer-Myrvold algorithm [boyer-cutting-2004], and its faces are traversed, in time \(O(V + E)\). By Euler’s formula, a connected planar graph has \(E - V + 2\) faces, including the outer face; a bridge appears twice along the face that contains it. Parallel edges and self-loops are ignored.

References

[boyer-cutting-2004]

John M. Boyer and Wendy J. Myrvold, “On the cutting edge: simplified O(n) planarity by edge addition”, Journal of Graph Algorithms and Applications 8(3), 241-273 (2004), DOI: 10.7155/jgaa.00091 [sci-hub, @tor]

Examples

>>> g = gt.lattice([3, 3])
>>> faces = gt.planar_faces(g)
>>> print(len(faces), sorted(len(f) for f in faces))
5 [4, 4, 4, 4, 8]