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.Tue, 10 Oct 2017 13:51:09 -0500Projection along affine hullhttp://ask.sagemath.org/question/35487/projection-along-affine-hull/Let `n_1,...,n_r` be integral points in a polyhedron `P`. The paper I am reading refers to "the projection of `P` along `aff(n_1,...,n_r)`". Here `aff(n_1,...,n_r)` is the affine hull of `n_1,...,n_r`. Can I accomplish this projection in sage?Tue, 08 Nov 2016 13:09:57 -0600http://ask.sagemath.org/question/35487/projection-along-affine-hull/Comment by jipilab for <p>Let <code>n_1,...,n_r</code> be integral points in a polyhedron <code>P</code>. The paper I am reading refers to "the projection of <code>P</code> along <code>aff(n_1,...,n_r)</code>". Here <code>aff(n_1,...,n_r)</code> is the affine hull of <code>n_1,...,n_r</code>. Can I accomplish this projection in sage?</p>
http://ask.sagemath.org/question/35487/projection-along-affine-hull/?comment=39098#post-id-39098Could we have a precise definition of what is meant by "projection of `P` along the affine hull"? This would make the question more precise.Tue, 10 Oct 2017 12:55:27 -0500http://ask.sagemath.org/question/35487/projection-along-affine-hull/?comment=39098#post-id-39098Answer by jipilab for <p>Let <code>n_1,...,n_r</code> be integral points in a polyhedron <code>P</code>. The paper I am reading refers to "the projection of <code>P</code> along <code>aff(n_1,...,n_r)</code>". Here <code>aff(n_1,...,n_r)</code> is the affine hull of <code>n_1,...,n_r</code>. Can I accomplish this projection in sage?</p>
http://ask.sagemath.org/question/35487/projection-along-affine-hull/?answer=39099#post-id-39099Here is an example. It requires to load the `Projection` function:
sage: from sage.geometry.polyhedron.plot import Projection
Let's say we have the following polytope:
sage: P = Polyhedron(vertices=[[-2,0,3],[2,0,3],[0,2,1],[0,-2,1]])
and we are interested in the affine space spanned by the points
sage: affine_basis = [vector([1,1,2]),vector([1,-1,2]),vector([-1,-1,2])]
we first get a linear subspace and create the projection matrix:
sage: linear_subspace = [ap - affine_points[0] for ap in affine_basis[1:]]
sage: VS = VectorSpace(QQ,3)
sage: proj_matrix = matrix([sum([v.inner_product(lv)*lv/(lv.inner_product(lv)) for lv in linear_subspace]) for v in VS.basis()]).transpose()
Then, we create a function that will emulate the affine projection (notice the addition of the first element of the affine basis).
sage: def my_proj(x): return proj_matrix*x + affine_basis[0]
Then, we project the polytope and use the transformed coordinates of the vertices to create a new polytope.
sage: proj_p = Projection(P,proj=my_proj)
sage: projected_P = Polyhedron(vertices=proj_p.transformed_coords)
Now, we can see the difference between
sage: P
A 3-dimensional polyhedron in ZZ^3 defined as the convex hull of 4 vertices
sage: P.vertices()
(A vertex at (-2, 0, 3),
A vertex at (0, -2, 1),
A vertex at (0, 2, 1),
A vertex at (2, 0, 3))
and the resulting polytope:
sage: projected_P
A 2-dimensional polyhedron in QQ^3 defined as the convex hull of 4 vertices
sage: projected_P.vertices()
(A vertex at (0, -2, 2),
A vertex at (0, 0, 2),
A vertex at (2, 2, 2),
A vertex at (2, 4, 2))Tue, 10 Oct 2017 13:51:09 -0500http://ask.sagemath.org/question/35487/projection-along-affine-hull/?answer=39099#post-id-39099