Ask Your Question
0

Vertices of Polytope

asked 2017-06-27 22:15:34 +0200

krishna gravatar image

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 flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2017-06-28 13:57:42 +0200

dan_fulea gravatar image

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()[0]

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.

edit flag offensive delete link more

Comments

This is very helpful, thanks for your detailed response!

krishna gravatar imagekrishna ( 2017-06-28 19:56:33 +0200 )edit
0

answered 2017-06-28 14:03:03 +0200

mforets gravatar image

updated 2017-06-28 14:04:38 +0200

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-06-27 22:15:34 +0200

Seen: 682 times

Last updated: Jun 28 '17