Ask Your Question

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

1 Answer

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[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 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

Comments

Thanks! Helped a lot :)

( 2015-04-20 18:45:20 +0200 )edit
1

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

sage: P1 & P2

( 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

Stats

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

Seen: 284 times

Last updated: Apr 20 '15