Visualization of polyhedron objects in Sage#
Author: sarah-marie belcastro <smbelcas@toroidalsnark.net>, Jean-Philippe Labbé <labbe@math.fu-berlin.de>
There are different ways to visualize polyhedron object of dimension at most 4.
render_solid
#
This plots the polyhedron as a solid. You can also adjust the opacity
parameter.
sage: Cube = polytopes.cube()
sage: Cube.render_solid(opacity=0.7)
Graphics3d Object
>>> from sage.all import *
>>> Cube = polytopes.cube()
>>> Cube.render_solid(opacity=RealNumber('0.7'))
Graphics3d Object
render_wireframe
#
This plots the graph (with unbounded edges) of the polyhedron
sage: Cube.render_wireframe()
Graphics3d Object
>>> from sage.all import *
>>> Cube.render_wireframe()
Graphics3d Object
plot
#
The plot
method draws the graph, the polygons and vertices of the
polyhedron all together.
sage: Cube.plot()
Graphics3d Object
>>> from sage.all import *
>>> Cube.plot()
Graphics3d Object
show
#
This is similar to plot
but does not return an object that you can
manipulate.
schlegel_projection
#
It is possible to visualize 4-dimensional polytopes using a schlegel diagram.
sage: HC = polytopes.hypercube(4)
sage: HC.schlegel_projection()
The projection of a polyhedron into 3 dimensions
sage: HC.schlegel_projection().plot()
Graphics3d Object
>>> from sage.all import *
>>> HC = polytopes.hypercube(Integer(4))
>>> HC.schlegel_projection()
The projection of a polyhedron into 3 dimensions
>>> HC.schlegel_projection().plot()
Graphics3d Object
We can see it from a different perspective by choosing point at a different distance:
sage: HC.schlegel_projection(position=1/4).plot()
Graphics3d Object
>>> from sage.all import *
>>> HC.schlegel_projection(position=Integer(1)/Integer(4)).plot()
Graphics3d Object
It is possible to choose from which facet one sees the projection:
sage: tHC = HC.face_truncation(HC.faces(0)[0])
sage: tHC.facets()
(A 3-dimensional face of a Polyhedron in QQ^4 defined as the convex hull of 10 vertices,
A 3-dimensional face of a Polyhedron in QQ^4 defined as the convex hull of 10 vertices,
A 3-dimensional face of a Polyhedron in QQ^4 defined as the convex hull of 10 vertices,
A 3-dimensional face of a Polyhedron in QQ^4 defined as the convex hull of 10 vertices,
A 3-dimensional face of a Polyhedron in QQ^4 defined as the convex hull of 4 vertices,
A 3-dimensional face of a Polyhedron in QQ^4 defined as the convex hull of 8 vertices,
A 3-dimensional face of a Polyhedron in QQ^4 defined as the convex hull of 8 vertices,
A 3-dimensional face of a Polyhedron in QQ^4 defined as the convex hull of 8 vertices,
A 3-dimensional face of a Polyhedron in QQ^4 defined as the convex hull of 8 vertices)
sage: tHC.schlegel_projection(tHC.facets()[4]).plot()
Graphics3d Object
>>> from sage.all import *
>>> tHC = HC.face_truncation(HC.faces(Integer(0))[Integer(0)])
>>> tHC.facets()
(A 3-dimensional face of a Polyhedron in QQ^4 defined as the convex hull of 10 vertices,
A 3-dimensional face of a Polyhedron in QQ^4 defined as the convex hull of 10 vertices,
A 3-dimensional face of a Polyhedron in QQ^4 defined as the convex hull of 10 vertices,
A 3-dimensional face of a Polyhedron in QQ^4 defined as the convex hull of 10 vertices,
A 3-dimensional face of a Polyhedron in QQ^4 defined as the convex hull of 4 vertices,
A 3-dimensional face of a Polyhedron in QQ^4 defined as the convex hull of 8 vertices,
A 3-dimensional face of a Polyhedron in QQ^4 defined as the convex hull of 8 vertices,
A 3-dimensional face of a Polyhedron in QQ^4 defined as the convex hull of 8 vertices,
A 3-dimensional face of a Polyhedron in QQ^4 defined as the convex hull of 8 vertices)
>>> tHC.schlegel_projection(tHC.facets()[Integer(4)]).plot()
Graphics3d Object
tikz
#
This method returns a tikz picture of the polytope (must be 2 or 3-dimensional). For more detail see the tutorial Draw polytopes in LaTeX using TikZ.
sage: c = polytopes.cube()
sage: c.tikz(output_type='TikzPicture')
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}%
[x={(1.000000cm, 0.000000cm)},
y={(-0.000000cm, 1.000000cm)},
z={(0.000000cm, -0.000000cm)},
scale=1.000000,
...
Use print to see the full content.
...
\node[vertex] at (-1.00000, -1.00000, 1.00000) {};
\node[vertex] at (-1.00000, 1.00000, 1.00000) {};
%%
%%
\end{tikzpicture}
\end{document}
>>> from sage.all import *
>>> c = polytopes.cube()
>>> c.tikz(output_type='TikzPicture')
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}%
[x={(1.000000cm, 0.000000cm)},
y={(-0.000000cm, 1.000000cm)},
z={(0.000000cm, -0.000000cm)},
scale=1.000000,
...
Use print to see the full content.
...
\node[vertex] at (-1.00000, -1.00000, 1.00000) {};
\node[vertex] at (-1.00000, 1.00000, 1.00000) {};
%%
%%
\end{tikzpicture}
\end{document}