Ask Your Question
0

Compute the centroid of a polytope

asked 2011-04-27 15:50:26 +0100

adk gravatar image

updated 2011-04-28 19:58:59 +0100

Does SAGE have a way to compute the center of mass of a polytope? I tried using polymake's centroid method, but that returned an error because the dimension of my polytope is not equal to the ambient dimension. I've read the manual and looked at the available functions but can't seem to find a SAGE command to do this. Does it exist?

EDIT: By request here's some sample _polymake_ code that fails (I'm not sure why this would be useful unless SAGE is using polymake under the hood):

polytope > $q=permutahedron(3);

polytope > print $q->CENTROID;

polymake: WARNING: could not compute 'CENTROID' probably because of unsatisfied preconditions:

precondition : DIM, AMBIENT_DIM ( CENTROID, VOLUME : VERTICES, TRIANGULATION.FACETS )

I'm guessing the error occurs because the ambient dimension of this polytope is 4 but the actual dimension of the polytope is 3; this is the same reason polymake tells me the volume of q is 0.

edit retag flag offensive close merge delete

Comments

Could you post some example code? It's easier to debug why a command wouldn't work.

cswiercz gravatar imagecswiercz ( 2011-04-27 17:16:54 +0100 )edit

My apologies. I hadn't read your question carefully enough to realize that you hadn't attempted to write any Sage code to compute the centroid.

cswiercz gravatar imagecswiercz ( 2011-04-30 15:40:15 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
3

answered 2011-05-07 15:52:26 +0100

Volker Braun gravatar image

There is no such function currently implemented. However, it would not be difficult to add. The straightforward approach would be to triangulate the polytope, find the barycenter of the simplices, and then add their individual barycenters weighted by the fraction of the total mass.

If you want to contribute a centroid method make a trac ticket and cc me, I'd be happy to help.

edit flag offensive delete link more

Comments

I have implemented this approach in https://trac.sagemath.org/ticket/29382.

Jonathan Kliem gravatar imageJonathan Kliem ( 2020-03-27 11:45:05 +0100 )edit

... which will be accessible with the command

sage: q = polytopes.permutahedron(4)
sage: q.centroid()
jipilab gravatar imagejipilab ( 2020-04-23 09:48:39 +0100 )edit
0

answered 2011-04-29 02:20:19 +0100

benjaminfjones gravatar image

The "center" (average of the vertices) is available via the center method like so:

sage: q = polytopes.permutahedron(4)
sage: q.dim()
3
sage: q.center()
(1/40000, 1/40000, 1/20000)

You can look through the other methods available in the Polyhedra documentation.

edit flag offensive delete link more

Comments

Thanks for the suggestion, but I'm not looking for the average of the vertices; I'm looking for the center of mass. I looked through the Polyhedra documentation and was unable to find a suitable command which is why I asked this question. Most likely no such command exists, but I thought I'd check to be sure.

adk gravatar imageadk ( 2011-04-29 04:21:06 +0100 )edit

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2011-04-27 15:50:26 +0100

Seen: 1,320 times

Last updated: May 07 '11