Plotting polyhedron with Makie

I am new to Julia and my question and problem may be really simple. I am trying to plot a polyhedron with Makie. I have been following the examples provided by the documentation for the Polyhedra package here and here, but can’t get it work. This is what I get when I try the example in the first link

>>> using Makie, CDDLib, Combinatorics, Polyhedra
>>> v = convexhull([0, 0, 0]) + conichull([1, 0, 0], [0, 1, 0], [0, 0, 1])
V-representation Polyhedra.Hull{Int64,Array{Int64,1},Int64}:
1-element iterator of Array{Int64,1}:
 [0, 0, 0],
3-element iterator of Ray{Int64,Array{Int64,1}}:
 Ray([1, 0, 0])
 Ray([0, 1, 0])
 Ray([0, 0, 1])
>>>
>>> p = polyhedron(v)
Polyhedron DefaultPolyhedron{Rational{BigInt},Polyhedra.Intersection{Rational{BigInt},Array{Rational{BigInt},1},Int64},Polyhedra.Hull{Rational{BigInt},Array{Rational{BigInt},1},Int64}}:
1-element iterator of Array{Rational{BigInt},1}:
 Rational{BigInt}[0//1, 0//1, 0//1],
3-element iterator of Ray{Rational{BigInt},Array{Rational{BigInt},1}}:
 Ray(Rational{BigInt}[1//1, 0//1, 0//1])
 Ray(Rational{BigInt}[0//1, 1//1, 0//1])
 Ray(Rational{BigInt}[0//1, 0//1, 1//1])
>>>
>>> m = Polyhedra.Mesh(p)
Polyhedra.Mesh{3,Rational{BigInt},DefaultPolyhedron{Rational{BigInt},Polyhedra.Intersection{Rational{BigInt},Array{Rational{BigInt},1},Int64},Polyhedra.Hull{Rational{BigInt},Array{Rational{BigInt},1},Int64}}}(convexhull([0//1, 0//1, 0//1]) + convexhull(Ray(Rational{BigInt}[1//1, 0//1, 0//1]), Ray(Rational{BigInt}[0//1, 1//1, 0//1]), Ray(Rational{BigInt}[0//1, 0//1, 1//1])))
>>>
>>> mesh(m, color=:blue)
MethodError: no method matching iterate(::Polyhedra.Mesh{3,Float64,CDDLib.Polyhedron{Float64}})
Closest candidates are:
  iterate(!Matched::Core.SimpleVector) at essentials.jl:603
  iterate(!Matched::Core.SimpleVector, !Matched::Any) at essentials.jl:603
  iterate(!Matched::ExponentialBackOff) at error.jl:253
  ...

Stacktrace:
 [1] isempty(::Polyhedra.Mesh{3,Float64,CDDLib.Polyhedron{Float64}}) at ./essentials.jl:739
 [2] xyz_boundingbox(::Function, ::Polyhedra.Mesh{3,Float64,CDDLib.Polyhedron{Float64}}) at /Users/jeremy/.julia/packages/AbstractPlotting/q9DyS/src/layouting/data_limits.jl:64
 [3] atomic_limits(::Mesh{...}) at /Users/jeremy/.julia/packages/AbstractPlotting/q9DyS/src/layouting/data_limits.jl:17
 [4] data_limits at /Users/jeremy/.julia/packages/AbstractPlotting/q9DyS/src/layouting/data_limits.jl:9 [inlined]
 [5] push!(::Scene, ::Mesh{...}) at /Users/jeremy/.julia/packages/AbstractPlotting/q9DyS/src/scenes.jl:347
 [6] plot!(::Scene, ::Type{Mesh{...}}, ::Attributes, ::Tuple{Observable{Polyhedra.Mesh{3,Float64,CDDLib.Polyhedron{Float64}}}}, ::Observable{Tuple{Polyhedra.Mesh{3,Float64,CDDLib.Polyhedron{Float64}}}}) at /Users/jeremy/.julia/packages/AbstractPlotting/q9DyS/src/interfaces.jl:653
 [7] plot!(::Scene, ::Type{Mesh{...}}, ::Attributes, ::Polyhedra.Mesh{3,Float64,CDDLib.Polyhedron{Float64}}; kw_attributes::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /Users/jeremy/.julia/packages/AbstractPlotting/q9DyS/src/interfaces.jl:580
 [8] plot! at /Users/jeremy/.julia/packages/AbstractPlotting/q9DyS/src/interfaces.jl:549 [inlined]
 [9] mesh(::Polyhedra.Mesh{3,Float64,CDDLib.Polyhedron{Float64}}; attributes::Base.Iterators.Pairs{Symbol,Symbol,Tuple{Symbol},NamedTuple{(:color,),Tuple{Symbol}}}) at /Users/jeremy/.julia/packages/AbstractPlotting/q9DyS/src/recipes.jl:15
 [10] top-level scope at In[50]:1

and this is what I get following the example in the second link

>>> using Makie, CDDLib, Combinatorics, Polyhedra, Pkg
>>> 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]
>>>
>>> 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]
>>>
>>> v1 = [1, -1,  0,  0];
>>> v2 = [1,  1, -2,  0];
>>> v3 = [1,  1,  1, -3];
>>> p3 = project(p4, [v1 v2 v3])
Polyhedron CDDLib.Polyhedron{Float64}:
14-element iterator of HalfSpace{Float64,Array{Float64,1}}:
 HalfSpace([-0.0, 3.2659863237109077, -1.1547005383792528], 6.0)
 HalfSpace([1.4142135623730951, 0.8164965809277264, -1.154700538379252], 3.9999999999999996)
 HalfSpace([-0.0, -0.0, -1.1547005383792515], 2.0)
 HalfSpace([-1.4142135623730956, 0.8164965809277265, -1.1547005383792524], 3.999999999999999)
 HalfSpace([-2.8284271247461894, -1.6329931618554518, -1.1547005383792515], 6.0)
 HalfSpace([-0.0, -1.6329931618554516, -1.154700538379251], 4.000000000000001)
 HalfSpace([-1.4142135623730951, -0.8164965809277264, 1.154700538379252], 4.000000000000002)
 HalfSpace([-0.0, -3.2659863237109077, 1.1547005383792528], 6.000000000000011)
 HalfSpace([-2.8284271247461885, 1.6329931618554516, 1.154700538379251], 5.999999999999995)
 HalfSpace([2.8284271247461885, -1.6329931618554516, -1.154700538379251], 6.0)
 HalfSpace([1.4142135623730956, -0.8164965809277265, 1.1547005383792524], 4.0000000000000036)
 HalfSpace([-0.0, -0.0, 1.1547005383792515], 2.0)
 HalfSpace([-0.0, 1.6329931618554516, 1.154700538379251], 3.9999999999999964)
 HalfSpace([2.8284271247461894, 1.6329931618554518, 1.1547005383792515], 5.9999999999999964)
>>>
>>> m = Polyhedra.Mesh(p3)
Polyhedra.Mesh{3,Float64,CDDLib.Polyhedron{Float64}}(HalfSpace([-0.0, 3.2659863237109077, -1.1547005383792528], 6.0) ∩ HalfSpace([1.4142135623730951, 0.8164965809277264, -1.154700538379252], 3.9999999999999996) ∩ HalfSpace([-0.0, -0.0, -1.1547005383792515], 2.0) ∩ HalfSpace([-1.4142135623730956, 0.8164965809277265, -1.1547005383792524], 3.999999999999999) ∩ HalfSpace([-2.8284271247461894, -1.6329931618554518, -1.1547005383792515], 6.0) ∩ HalfSpace([-0.0, -1.6329931618554516, -1.154700538379251], 4.000000000000001) ∩ HalfSpace([-1.4142135623730951, -0.8164965809277264, 1.154700538379252], 4.000000000000002) ∩ HalfSpace([-0.0, -3.2659863237109077, 1.1547005383792528], 6.000000000000011) ∩ HalfSpace([-2.8284271247461885, 1.6329931618554516, 1.154700538379251], 5.999999999999995) ∩ HalfSpace([2.8284271247461885, -1.6329931618554516, -1.154700538379251], 6.0) ∩ HalfSpace([1.4142135623730956, -0.8164965809277265, 1.1547005383792524], 4.0000000000000036) ∩ HalfSpace([-0.0, -0.0, 1.1547005383792515], 2.0) ∩ HalfSpace([-0.0, 1.6329931618554516, 1.154700538379251], 3.9999999999999964) ∩ HalfSpace([2.8284271247461894, 1.6329931618554518, 1.1547005383792515], 5.9999999999999964))
>>>
>>>mesh(m, color=:blue)
MethodError: no method matching iterate(::Polyhedra.Mesh{3,Float64,CDDLib.Polyhedron{Float64}})
Closest candidates are:
  iterate(!Matched::Core.SimpleVector) at essentials.jl:603
  iterate(!Matched::Core.SimpleVector, !Matched::Any) at essentials.jl:603
  iterate(!Matched::ExponentialBackOff) at error.jl:253
  ...

Stacktrace:
 [1] isempty(::Polyhedra.Mesh{3,Float64,CDDLib.Polyhedron{Float64}}) at ./essentials.jl:739
 [2] xyz_boundingbox(::Function, ::Polyhedra.Mesh{3,Float64,CDDLib.Polyhedron{Float64}}) at /Users/jeremy/.julia/packages/AbstractPlotting/q9DyS/src/layouting/data_limits.jl:64
 [3] atomic_limits(::Mesh{...}) at /Users/jeremy/.julia/packages/AbstractPlotting/q9DyS/src/layouting/data_limits.jl:17
 [4] data_limits at /Users/jeremy/.julia/packages/AbstractPlotting/q9DyS/src/layouting/data_limits.jl:9 [inlined]
 [5] push!(::Scene, ::Mesh{...}) at /Users/jeremy/.julia/packages/AbstractPlotting/q9DyS/src/scenes.jl:347
 [6] plot!(::Scene, ::Type{Mesh{...}}, ::Attributes, ::Tuple{Observable{Polyhedra.Mesh{3,Float64,CDDLib.Polyhedron{Float64}}}}, ::Observable{Tuple{Polyhedra.Mesh{3,Float64,CDDLib.Polyhedron{Float64}}}}) at /Users/jeremy/.julia/packages/AbstractPlotting/q9DyS/src/interfaces.jl:653
 [7] plot!(::Scene, ::Type{Mesh{...}}, ::Attributes, ::Polyhedra.Mesh{3,Float64,CDDLib.Polyhedron{Float64}}; kw_attributes::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /Users/jeremy/.julia/packages/AbstractPlotting/q9DyS/src/interfaces.jl:580
 [8] plot! at /Users/jeremy/.julia/packages/AbstractPlotting/q9DyS/src/interfaces.jl:549 [inlined]
 [9] mesh(::Polyhedra.Mesh{3,Float64,CDDLib.Polyhedron{Float64}}; attributes::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /Users/jeremy/.julia/packages/AbstractPlotting/q9DyS/src/recipes.jl:15
 [10] mesh(::Polyhedra.Mesh{3,Float64,CDDLib.Polyhedron{Float64}}) at /Users/jeremy/.julia/packages/AbstractPlotting/q9DyS/src/recipes.jl:13
 [11] top-level scope at In[49]:1
>>>
>>> Pkg.status()
Status `~/.julia/environments/v1.4/Project.toml`
  [3391f64e] CDDLib v0.6.2
  [861a8166] Combinatorics v1.0.2
  [b4f34e82] Distances v0.9.0
  [31c24e10] Distributions v0.23.4
  [7073ff75] IJulia v1.21.2
  [ee78f7c6] Makie v0.11.0
  [67491407] Polyhedra v0.6.5
  [438e738f] PyCall v1.91.4
  [a8468747] QHull v0.2.0
  [37e2e46d] LinearAlgebra 

How can I get these examples to work?

Issue opened:MethodError with Makie's mesh · Issue #215 · JuliaPolyhedra/Polyhedra.jl · GitHub

1 Like

Please note that the issue linked in my previous comment was fixed a while ago. For instance,

julia> using Makie, CDDLib, Polyhedra

julia> v = convexhull([0, 0, 0]) + conichull([1, 0, 0], [0, 1, 0], [0, 0, 1]);

julia> p = polyhedron(v);

julia> m = Polyhedra.Mesh(p);

julia> X = mesh(m, color=:blue)

Result:

6 Likes

The extreme points in the figure all go to 2 even though you specified 1. Is there a way to fix this?

Here is a working code:

julia> using LazySets, Polyhedra, GLMakie

julia> P = VPolytope([[0, 0, 0.], [1, 0, 0.], [0, 1, 0.], [0, 0, 1.]]);

julia> plot3d(P)

2 Likes