Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The following works for me:

TYPES = ( int, sage.rings.integer.Integer )

def get_face( P, verticesInput ):
    """Here, <P> is a polyhedron, 
    and the <verticesInput> are a list of true vertices of the polyhedron.
    Then we search for a face of the polyhedron having the given <verticesInput>
    matching the own vertices. If found, we return it. If not we return None.
    """

    verticesP = P.vertices()
    verticesSetInput = set( [ verticesP[ v ] if type(v) in TYPES else v
                              for v in verticesInput ] )

    if len( verticesInput ) != len( verticesSetInput ):
        return

    for f in P.face_lattice():
        if set( f.vertices() ) == verticesSetInput:
            return f

P = polytopes.dodecahedron()
# test
for data in ( [0..3], [0..4], [0..5], [15..19], {8,15}, (7,) ):
    f = get_face( P, data )
    if f:    print "data = %s --> FOUND FACE %s" % ( data, f )
    else:    print "data = %s --> NO SUCH FACE"  % ( data )

It gives:

data = [0, 1, 2, 3] --> NO SUCH FACE
data = [0, 1, 2, 3, 4] --> FOUND FACE <0,1,2,3,4>
data = [0, 1, 2, 3, 4, 5] --> NO SUCH FACE
data = [15, 16, 17, 18, 19] --> FOUND FACE <15,16,17,18,19>
data = set([8, 15]) --> FOUND FACE <8,15>
data = (7,) --> FOUND FACE <7>