ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 05 Jul 2018 06:47:46 -0500Can I intersect the boundaries of two polyhedra and display it?http://ask.sagemath.org/question/26602/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?Sun, 19 Apr 2015 16:38:58 -0500http://ask.sagemath.org/question/26602/can-i-intersect-the-boundaries-of-two-polyhedra-and-display-it/Answer by vdelecroix for <p>I need to show the intersection of two polyhedra's facets (orthoplexes for this case). Any nice way to do that?</p>
http://ask.sagemath.org/question/26602/can-i-intersect-the-boundaries-of-two-polyhedra-and-display-it/?answer=26604#post-id-26604Hello,
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.
VincentSun, 19 Apr 2015 16:51:20 -0500http://ask.sagemath.org/question/26602/can-i-intersect-the-boundaries-of-two-polyhedra-and-display-it/?answer=26604#post-id-26604Comment by jipilab for <p>Hello,</p>
<p>Given a polyhedron you can obtain their faces with the method faces. Then you can convert them to polyhedra and intersect them. In action</p>
<pre><code>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)]
</code></pre>
<p>f1 is just the faces of my first polyhedron (seen themselves as polyhedra)</p>
<pre><code>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]]
</code></pre>
<p>idem for f2</p>
<pre><code>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]]
</code></pre>
<p>And you can now do intersection between them</p>
<pre><code>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
</code></pre>
<p>Then, for plotting a polyhedra <strong>P</strong> just do <strong>P.plot()</strong> or <strong>P.show()</strong>. To see the options you have for plotting, you can have a look at the documentation obtained by typing enter after <strong>P.plot?</strong> or <strong>P.show?</strong> (with the question mark). There is also the possibility to make a tikz picture if you are interested.</p>
<p>Vincent</p>
http://ask.sagemath.org/question/26602/can-i-intersect-the-boundaries-of-two-polyhedra-and-display-it/?comment=42830#post-id-42830You can also do the intersection operation by using "&":
sage: P1 & P2Thu, 05 Jul 2018 06:47:46 -0500http://ask.sagemath.org/question/26602/can-i-intersect-the-boundaries-of-two-polyhedra-and-display-it/?comment=42830#post-id-42830Comment by RoyJac for <p>Hello,</p>
<p>Given a polyhedron you can obtain their faces with the method faces. Then you can convert them to polyhedra and intersect them. In action</p>
<pre><code>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)]
</code></pre>
<p>f1 is just the faces of my first polyhedron (seen themselves as polyhedra)</p>
<pre><code>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]]
</code></pre>
<p>idem for f2</p>
<pre><code>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]]
</code></pre>
<p>And you can now do intersection between them</p>
<pre><code>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
</code></pre>
<p>Then, for plotting a polyhedra <strong>P</strong> just do <strong>P.plot()</strong> or <strong>P.show()</strong>. To see the options you have for plotting, you can have a look at the documentation obtained by typing enter after <strong>P.plot?</strong> or <strong>P.show?</strong> (with the question mark). There is also the possibility to make a tikz picture if you are interested.</p>
<p>Vincent</p>
http://ask.sagemath.org/question/26602/can-i-intersect-the-boundaries-of-two-polyhedra-and-display-it/?comment=26609#post-id-26609Thanks! Helped a lot :)Mon, 20 Apr 2015 11:45:20 -0500http://ask.sagemath.org/question/26602/can-i-intersect-the-boundaries-of-two-polyhedra-and-display-it/?comment=26609#post-id-26609