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

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

edit retag close merge delete

Sort by » oldest newest most voted

Hello,

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.vertices_list()
[[0, 0], [1, 2]]
sage: f1.vertices_list()
[[0, 0], [3, 4]]
sage: f1.vertices_list()
[[1, 2], [3, 4]]


idem for f2

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


And you can now do intersection between them

sage: f1.intersection(f2)
A 0-dimensional polyhedron in ZZ^2 defined as the convex hull of 1 vertex
sage: f1.intersection(f2)
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 P.show(). To see the options you have for plotting, you can have a look at the documentation obtained by typing enter after P.plot? or P.show? (with the question mark). There is also the possibility to make a tikz picture if you are interested.

Vincent

more

1

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

sage: P1 & P2