# Vertices of Polytope

Hi!

I have a list of points that I'm using to construct a convex, finite-sided, compact polytope:

P1 = Polyhedron(vertices = [list_of_points])


I know how to extract from P1 the list of vertices that define it:

vertex_list=[]
for q in P1.Vrepresentation():
vertex_list.append(q)
print('vertices ='), vertex_list


This returns the following output:

vertices = [A vertex at (0.5, 0.0), A vertex at (-0.5, 0.0), A vertex at (-0.5, 1.0), A vertex at (0.5, -1.0)]


But what I'd like to do is have a list of the coordinates of the vertices only: i.e have sage tell me a list of the form [(.5,0), (-.5, 0), (-.5, 1), (.5, -1)], so that I can do some computations about P1 that are dependent on the coordinates of the vertices. Is there a way to do this?

Thanks!

edit retag close merge delete

Sort by » oldest newest most voted

The following code gets the (3D) vertices as list, starting from a special polyhedron:

[ v.vector().list() for v in t.vertices() ]


For this, let us compare...

sage: t = polytopes.tetrahedron()
sage: t.vertices()
(A vertex at (0, 0, 0),
A vertex at (0, 1, 1),
A vertex at (1, 0, 1),
A vertex at (1, 1, 0))

sage: [ v.vector() for v in t.vertices() ]
[(0, 0, 0), (0, 1, 1), (1, 0, 1), (1, 1, 0)]

sage: [ v.vector().list() for v in t.vertices() ]
[[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 0]]

sage: v = t.vertices()

sage: print "v has type", type(v)
v has type <class 'sage.geometry.polyhedron.representation.Vertex'>

sage: print "v.vector() has type", type( v.vector() )
v.vector() has type <type 'sage.modules.vector_integer_dense.Vector_integer_dense'>

sage: print "v.vector().list() has type", type( v.vector().list() )
v.vector().list() has type <type 'list'>


It is always useful to look at one element, a vertex, instantiated as a variable v above, then to inspect its methods. Very often, the name will already be enough to guess the right needed method. Note that the vector representation of the vertices may also be enough.

more

Hint: use tab-completion, P.vert[TAB].

The method P.vertices_list() returns a list of vertices of the polyhedron, and P.vertex_generator() allows to conveniently iterate over them.

more