ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 25 Aug 2020 03:59:18 -0500Computing projection of a polyhedronhttps://ask.sagemath.org/question/48155/computing-projection-of-a-polyhedron/How to compute the projection of a given polyhedron onto a given smaller-dimensional plane?
E.g., the projection of Polyhedron(vertices=[(-1,-1), (1,3), (5,-2)]) onto the line $y=x$.Wed, 02 Oct 2019 19:08:37 -0500https://ask.sagemath.org/question/48155/computing-projection-of-a-polyhedron/Answer by jipilab for <p>How to compute the projection of a given polyhedron onto a given smaller-dimensional plane?</p>
<p>E.g., the projection of Polyhedron(vertices=[(-1,-1), (1,3), (5,-2)]) onto the line $y=x$.</p>
https://ask.sagemath.org/question/48155/computing-projection-of-a-polyhedron/?answer=48504#post-id-48504One possibility is the following.
First create the desired transformation as a matrix.
sage: nf = QuadraticField(2)
sage: sqrt2 = nf.gen()
sage: proj_mat = matrix(nf,[[sqrt2/2,sqrt2/2],[sqrt2/2,sqrt2/2]])
Then, create your polyhedron
sage: P = Polyhedron(vertices=[(-1,-1), (1,3), (5,-2)])
One then just need to apply the transformation on each vertices of the polyhedron and take the result back to a polyhedron.
sage: Pproj = Polyhedron(vertices = (proj_mat*P.vertices_matrix()).columns())
sage: Pproj
A 1-dimensional polyhedron in (Number Field in a with defining polynomial x^2 - 2)^2 defined as the convex hull of 2 vertices
sage: Pproj.vertices_list()
[[-a, -a], [2*a, 2*a]]
Currently, projections (or other linear transformations) are not implemented better than as above...Fri, 25 Oct 2019 17:17:43 -0500https://ask.sagemath.org/question/48155/computing-projection-of-a-polyhedron/?answer=48504#post-id-48504Comment by Jonathan Kliem for <p>One possibility is the following.</p>
<p>First create the desired transformation as a matrix.</p>
<pre><code>sage: nf = QuadraticField(2)
sage: sqrt2 = nf.gen()
sage: proj_mat = matrix(nf,[[sqrt2/2,sqrt2/2],[sqrt2/2,sqrt2/2]])
</code></pre>
<p>Then, create your polyhedron</p>
<pre><code>sage: P = Polyhedron(vertices=[(-1,-1), (1,3), (5,-2)])
</code></pre>
<p>One then just need to apply the transformation on each vertices of the polyhedron and take the result back to a polyhedron.</p>
<pre><code>sage: Pproj = Polyhedron(vertices = (proj_mat*P.vertices_matrix()).columns())
sage: Pproj
A 1-dimensional polyhedron in (Number Field in a with defining polynomial x^2 - 2)^2 defined as the convex hull of 2 vertices
sage: Pproj.vertices_list()
[[-a, -a], [2*a, 2*a]]
</code></pre>
<p>Currently, projections (or other linear transformations) are not implemented better than as above...</p>
https://ask.sagemath.org/question/48155/computing-projection-of-a-polyhedron/?comment=53164#post-id-53164The following answer should give you a step by step guide: https://ask.sagemath.org/question/35487/projection-along-affine-hull/?answer=50967#post-id-50967
In particular how to obtain the matrix that induces a projection to an affine span.Tue, 25 Aug 2020 03:59:18 -0500https://ask.sagemath.org/question/48155/computing-projection-of-a-polyhedron/?comment=53164#post-id-53164Comment by Jonathan Kliem for <p>One possibility is the following.</p>
<p>First create the desired transformation as a matrix.</p>
<pre><code>sage: nf = QuadraticField(2)
sage: sqrt2 = nf.gen()
sage: proj_mat = matrix(nf,[[sqrt2/2,sqrt2/2],[sqrt2/2,sqrt2/2]])
</code></pre>
<p>Then, create your polyhedron</p>
<pre><code>sage: P = Polyhedron(vertices=[(-1,-1), (1,3), (5,-2)])
</code></pre>
<p>One then just need to apply the transformation on each vertices of the polyhedron and take the result back to a polyhedron.</p>
<pre><code>sage: Pproj = Polyhedron(vertices = (proj_mat*P.vertices_matrix()).columns())
sage: Pproj
A 1-dimensional polyhedron in (Number Field in a with defining polynomial x^2 - 2)^2 defined as the convex hull of 2 vertices
sage: Pproj.vertices_list()
[[-a, -a], [2*a, 2*a]]
</code></pre>
<p>Currently, projections (or other linear transformations) are not implemented better than as above...</p>
https://ask.sagemath.org/question/48155/computing-projection-of-a-polyhedron/?comment=53154#post-id-53154In sage 9.1 one can skip the third part by just multiplying the matrix with the polyhedron: `proj_mat*P`.Mon, 24 Aug 2020 01:18:30 -0500https://ask.sagemath.org/question/48155/computing-projection-of-a-polyhedron/?comment=53154#post-id-53154