Ask Your Question

Can I intersect the boundaries of two polyhedra and display it?

asked 2015-04-19 23:38:58 +0200

RoyJac gravatar image

I need to show the intersection of two polyhedra's facets (orthoplexes for this case). Any nice way to do that?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-04-19 23:51:20 +0200

vdelecroix gravatar image

updated 2015-04-20 00:19:32 +0200


Given a polyhedron you can obtain their faces with the method faces. Then you can convert them to polyhedra and intersect them. In action

sage: P1 = Polyhedron([(0,0),(1,2),(3,4)])
sage: P2 = Polyhedron([(0,0),(1,2),(-3,-2)])
sage: f1 = [f.as_polyhedron() for f in P1.faces(1)]
sage: f2 = [f.as_polyhedron() for f in P2.faces(1)]

f1 is just the faces of my first polyhedron (seen themselves as polyhedra)

sage: f1[0].vertices_list()
[[0, 0], [1, 2]]
sage: f1[1].vertices_list()
[[0, 0], [3, 4]]
sage: f1[2].vertices_list()
[[1, 2], [3, 4]]

idem for f2

sage: f2[0].vertices_list()
[[-3, -2], [0, 0]]
sage: f2[1].vertices_list()
[[-3, -2], [1, 2]]
sage: f2[2].vertices_list()
[[0, 0], [1, 2]]

And you can now do intersection between them

sage: f1[0].intersection(f2[0])
A 0-dimensional polyhedron in ZZ^2 defined as the convex hull of 1 vertex
sage: f1[0].intersection(f2[2])
A 1-dimensional polyhedron in ZZ^2 defined as the convex hull of 2 vertices

Then, for plotting a polyhedra P just do P.plot() or To see the options you have for plotting, you can have a look at the documentation obtained by typing enter after P.plot? or (with the question mark). There is also the possibility to make a tikz picture if you are interested.


edit flag offensive delete link more


Thanks! Helped a lot :)

RoyJac gravatar imageRoyJac ( 2015-04-20 18:45:20 +0200 )edit

You can also do the intersection operation by using "&":

sage: P1 & P2
jipilab gravatar imagejipilab ( 2018-07-05 13:47:46 +0200 )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


Asked: 2015-04-19 23:38:58 +0200

Seen: 522 times

Last updated: Apr 20 '15