In this notebook we plot the permutahedron of order 4 which is a 3-dimensional polyhedron living in a 4-dimensional space. It is defined as the convex hull of all permutations of $(0, 1, 2, 3)$.
using Combinatorics, Polyhedra
v = vrep(collect(permutations([0, 1, 2, 3])))
V-representation Polyhedra.PointsHull{Int64,Array{Int64,1},Int64}: 24-element iterator of Array{Int64,1}: [0, 1, 2, 3] [0, 1, 3, 2] [0, 2, 1, 3] [0, 2, 3, 1] [0, 3, 1, 2] [0, 3, 2, 1] [1, 0, 2, 3] [1, 0, 3, 2] [1, 2, 0, 3] [1, 2, 3, 0] [1, 3, 0, 2] [1, 3, 2, 0] [2, 0, 1, 3] [2, 0, 3, 1] [2, 1, 0, 3] [2, 1, 3, 0] [2, 3, 0, 1] [2, 3, 1, 0] [3, 0, 1, 2] [3, 0, 2, 1] [3, 1, 0, 2] [3, 1, 2, 0] [3, 2, 0, 1] [3, 2, 1, 0]
To plot a polyhedron, we need both the H-representation and V-representation so we will need a library to do representation conversion. We choose CDD in floating point arithmetic.
using CDDLib
p4 = polyhedron(v, CDDLib.Library())
Polyhedron CDDLib.Polyhedron{Float64}: 24-element iterator of Array{Float64,1}: [0.0, 1.0, 2.0, 3.0] [0.0, 1.0, 3.0, 2.0] [0.0, 2.0, 1.0, 3.0] [0.0, 2.0, 3.0, 1.0] [0.0, 3.0, 1.0, 2.0] [0.0, 3.0, 2.0, 1.0] [1.0, 0.0, 2.0, 3.0] [1.0, 0.0, 3.0, 2.0] [1.0, 2.0, 0.0, 3.0] [1.0, 2.0, 3.0, 0.0] [1.0, 3.0, 0.0, 2.0] [1.0, 3.0, 2.0, 0.0] [2.0, 0.0, 1.0, 3.0] [2.0, 0.0, 3.0, 1.0] [2.0, 1.0, 0.0, 3.0] [2.0, 1.0, 3.0, 0.0] [2.0, 3.0, 0.0, 1.0] [2.0, 3.0, 1.0, 0.0] [3.0, 0.0, 1.0, 2.0] [3.0, 0.0, 2.0, 1.0] [3.0, 1.0, 0.0, 2.0] [3.0, 1.0, 2.0, 0.0] [3.0, 2.0, 0.0, 1.0] [3.0, 2.0, 1.0, 0.0]
The permutahedron lives in a 4-dimension space but is 3-dimensional as it is contained in the hyperplane $x_1 + x_2 + x_3 + x_4 = 0 + 1 + 2 + 3 = 6$. We choose an orthogonal basis of this hyperplane: $(1, -1, 0, 0)$, $(1, 1, -2, 0)$ and $(1, 1, 1, -3)$.
v1 = [1, -1, 0, 0]
v2 = [1, 1, -2, 0]
v3 = [1, 1, 1, -3];
We project the polyhedron in this basis to obtain a full dimensional 3-dimensional polyhedron living in a 3-dimensional space.
p3 = project(p4, [v1 v2 v3])
Polyhedron CDDLib.Polyhedron{Float64}: 14-element iterator of HalfSpace{Float64,Array{Float64,1}}: HalfSpace([-0.0, 3.26599, -1.1547], 6.0) HalfSpace([1.41421, 0.816497, -1.1547], 3.9999999999999996) HalfSpace([-0.0, -0.0, -1.1547], 2.0) HalfSpace([-1.41421, 0.816497, -1.1547], 3.999999999999999) HalfSpace([-2.82843, -1.63299, -1.1547], 6.0) HalfSpace([-0.0, -1.63299, -1.1547], 4.000000000000001) HalfSpace([-1.41421, -0.816497, 1.1547], 4.000000000000002) HalfSpace([-0.0, -3.26599, 1.1547], 6.000000000000011) HalfSpace([-2.82843, 1.63299, 1.1547], 5.999999999999995) HalfSpace([2.82843, -1.63299, -1.1547], 6.0) HalfSpace([1.41421, -0.816497, 1.1547], 4.0000000000000036) HalfSpace([-0.0, -0.0, 1.1547], 2.0) HalfSpace([-0.0, 1.63299, 1.1547], 3.9999999999999964) HalfSpace([2.82843, 1.63299, 1.1547], 5.9999999999999964)
To get a plottable object, we transform the polyhedron into a mesh as follows.
m = Polyhedra.Mesh(p3);
using MeshCat
vis = Visualizer()
setobject!(vis, m)
IJuliaCell(vis)
using Makie
mesh(m, color=:blue)
using Makie
wireframe(m)