I am running the following code to get a plannar graph with a specific embedding:
import numpy as np
import matplotlib.pyplot as plt
import networkx as nx
#Defining the graph with pannar embedding
H=nx.PlanarEmbedding()
H.add_half_edge_cw(1,2,None)
H.add_half_edge_cw(2,1,None)
H.add_half_edge_ccw(2,3,1)
H.add_half_edge_ccw(3,2,None)
H.add_half_edge_ccw(3,1,2)
H.add_half_edge_cw(1,3,2)
H.add_half_edge_ccw(2,4,1)
H.add_half_edge_ccw(4,2,None)
H.add_half_edge_cw(4,3,2)
H.add_half_edge_cw(3,4,1)
#Try to plot the graph with the above embedding,
#if the embedding is not correct it prints 'Fail'
try:
H.check_structure()
pos=nx.combinatorial_embedding_to_pos(H)
nx.draw(H,pos,with_labels=True)
except:
print('Fail')
As an output I get:
But I was expecting to get the following embedding:
I don't undestand why my way of defining H is wrong.
Maybe I didn't understand exactly how this .add_half_edge_cw works, if someone could better explain it to me, I would be really thankful.
For example I added H.add_half_edge_ccw(2,4,1), which for me means that the counter-clockwise neighbor of 2-4 should be 2-1, but in the output it is clearly 2-3.
From the documentation:
Your assumption is:
The implementation appears to be, start with the existing edge
(2,1)
and, relative to node2
, go counter-clockwise and add the edge(2,4)
.You are assuming that the angular direction is measured from new-to-existing edges rather than the opposite existing-to-new edges.