# Sage and planar graphs How can I compute the faces of a planar embedding of a planar graph? And how to compute the dual of a plane graph?

edit retag close merge delete

Sort by » oldest newest most voted About the faces of a planar graph, you can try using the trace_faces method for Graphs. For example:

sage: g=graphs.IcosahedralGraph()
sage: g.is_planar(set_embedding=True)
True
sage: g.trace_faces(g.get_embedding())
[[(10, 11), (11, 7), (7, 10)],
[(6, 4), (4, 3), (3, 6)],
[(5, 6), (6, 1), (1, 5)],
[(2, 8), (8, 1), (1, 2)],
[(9, 8), (8, 2), (2, 9)],
[(8, 0), (0, 1), (1, 8)],
[(3, 2), (2, 6), (6, 3)],
[(0, 7), (7, 11), (11, 0)],
[(2, 1), (1, 6), (6, 2)],
[(8, 9), (9, 7), (7, 8)],
[(4, 10), (10, 3), (3, 4)],
[(5, 4), (4, 6), (6, 5)],
[(11, 4), (4, 5), (5, 11)],
[(10, 4), (4, 11), (11, 10)],
[(9, 3), (3, 10), (10, 9)],
[(7, 0), (0, 8), (8, 7)],
[(11, 5), (5, 0), (0, 11)],
[(10, 7), (7, 9), (9, 10)],
[(2, 3), (3, 9), (9, 2)],
[(5, 1), (1, 0), (0, 5)]]


As @Nathann mentions, there seems to be no code to get the dual. However there seems to be some code for this in trac, perhaps you can start from there.

more

Hey, I didn't even know this function existed ! The docstring begins by saying that it is "a helper function to compute the genus of a graph". What about renaming it to "faces" and updating the docstring ? Could you review the patch if I write that ?

Hmmmmm... I don't think that we have functions for this, though we already have the tools. The is_planar method can give you an "embedding" dictionary, which can then be used to list all faces. It would be nice to have functions to do that directly, though.

Well, if you feel like coding them and adding them to Sage, I think that it may not be that much work and be very helpful :-)

more

It would be probably best to modify is_planar to do it. Is the source for is_planar available? How can I get?

Of course the source is available! If g is a graph, you can access it by executing g.is_planar??. This seems to use the is_planar method from sage.graphs. I believe things get a bit complicated after this call.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8511387,"math_prob":0.9799945,"size":2175,"snap":"2019-51-2020-05","text_gpt3_token_len":790,"char_repetition_ratio":0.13450024,"word_repetition_ratio":0.1056701,"special_character_ratio":0.44229886,"punctuation_ratio":0.28373703,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9565998,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-12-10T22:12:43Z\",\"WARC-Record-ID\":\"<urn:uuid:40d4e28e-ac73-412d-b8e9-634e9ca75559>\",\"Content-Length\":\"68624\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:3bd5bbb6-8ddb-405e-978d-015eb1382c3a>\",\"WARC-Concurrent-To\":\"<urn:uuid:a12c70dc-a1ab-421d-beb0-47dcccb3d12d>\",\"WARC-IP-Address\":\"140.254.118.68\",\"WARC-Target-URI\":\"https://ask.sagemath.org/question/7904/sage-and-planar-graphs/\",\"WARC-Payload-Digest\":\"sha1:BDO2DL2XZKQGFQHKZ5AHXYFHGYHWUF3D\",\"WARC-Block-Digest\":\"sha1:U33U3WXMD7MHRMFIXU6VTVF67IKUHSFM\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-51/CC-MAIN-2019-51_segments_1575540529006.88_warc_CC-MAIN-20191210205200-20191210233200-00222.warc.gz\"}"}