'Edges of polytope in python

I have looked all over for this, but I can't find anything! I used pycddlib to get the vertices of a polytope from the inequalities representation. However, I need not only the vertices, but the edges as well. I can't find any packages to get them; convex hull libraries give facets or vertex lists but not edges.



Solution 1:[1]

Two vertices constitute an edge if both of them are on two planes.

If library doesn't return information about plane-vertex connectivity, than for each vertex check on which planes it is by putting it in inequalities. Than find pairs of vertices that share two planes.

Solution 2:[2]

You can get the edges as follows:

poly = pcdd.Polyhedron(mat)

# get the adjacent vertices of each vertex
adjacencies = [list(x) for x in poly.get_input_adjacency()]

# store the edges in a matrix (giving the indices of the points)
edges = []
for i,indices in enumerate(adjacencies[:-1]):
    indices = list(filter(lambda x: x>i, indices))
    l = len(indices)
    if l>0:
        col1 = np.full((l, 1), i)
        indices = np.reshape(indices, (l, 1))
        edges.append(np.hstack((col1, indices)))
Edges = np.vstack(tuple(edges))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ante
Solution 2 Stéphane Laurent