Functions for plotting polyhedra¶
-
class
sage.geometry.polyhedron.plot.
Projection
(polyhedron, proj=<function projection_func_identity at 0x7fd8a53a79b0>)¶ Bases:
sage.structure.sage_object.SageObject
The projection of a
Polyhedron
.This class keeps track of the necessary data to plot the input polyhedron.
-
coord_index_of
(v)¶ Convert a coordinate vector to its internal index.
EXAMPLES:
sage: p = polytopes.hypercube(3) sage: proj = p.projection() sage: proj.coord_index_of(vector((1,1,1))) 7
-
coord_indices_of
(v_list)¶ Convert list of coordinate vectors to the corresponding list of internal indices.
EXAMPLES:
sage: p = polytopes.hypercube(3) sage: proj = p.projection() sage: proj.coord_indices_of([vector((1,1,1)),vector((1,-1,1))]) [7, 5]
-
coordinates_of
(coord_index_list)¶ Given a list of indices, return the projected coordinates.
EXAMPLES:
sage: p = polytopes.simplex(4, project=True).projection() sage: p.coordinates_of([1]) [[-0.7071067812, 0.4082482905, 0.2886751346, 0.2236067977]]
-
identity
()¶ Return the identity projection of the polyhedron.
EXAMPLES:
sage: p = polytopes.icosahedron(exact=False) sage: from sage.geometry.polyhedron.plot import Projection sage: pproj = Projection(p) sage: ppid = pproj.identity() sage: ppid.dimension 3
-
render_0d
(point_opts={}, line_opts={}, polygon_opts={})¶ Return 0d rendering of the projection of a polyhedron into 2-dimensional ambient space.
INPUT:
See
plot()
.OUTPUT:
A 2-d graphics object.
EXAMPLES:
sage: print(Polyhedron([]).projection().render_0d().description()) sage: print(Polyhedron(ieqs=[(1,)]).projection().render_0d().description()) Point set defined by 1 point(s): [(0.0, 0.0)]
-
render_1d
(point_opts={}, line_opts={}, polygon_opts={})¶ Return 1d rendering of the projection of a polyhedron into 2-dimensional ambient space.
INPUT:
See
plot()
.OUTPUT:
A 2-d graphics object.
EXAMPLES:
sage: Polyhedron([(0,), (1,)]).projection().render_1d() Graphics object consisting of 2 graphics primitives
-
render_2d
(point_opts={}, line_opts={}, polygon_opts={})¶ Return 2d rendering of the projection of a polyhedron into 2-dimensional ambient space.
EXAMPLES:
sage: p1 = Polyhedron(vertices=[[1,1]], rays=[[1,1]]) sage: q1 = p1.projection() sage: p2 = Polyhedron(vertices=[[1,0], [0,1], [0,0]]) sage: q2 = p2.projection() sage: p3 = Polyhedron(vertices=[[1,2]]) sage: q3 = p3.projection() sage: p4 = Polyhedron(vertices=[[2,0]], rays=[[1,-1]], lines=[[1,1]]) sage: q4 = p4.projection() sage: q1.plot() + q2.plot() + q3.plot() + q4.plot() Graphics object consisting of 17 graphics primitives
-
render_3d
(point_opts={}, line_opts={}, polygon_opts={})¶ Return 3d rendering of a polyhedron projected into 3-dimensional ambient space.
EXAMPLES:
sage: p1 = Polyhedron(vertices=[[1,1,1]], rays=[[1,1,1]]) sage: p2 = Polyhedron(vertices=[[2,0,0], [0,2,0], [0,0,2]]) sage: p3 = Polyhedron(vertices=[[1,0,0], [0,1,0], [0,0,1]], rays=[[-1,-1,-1]]) sage: p1.projection().plot() + p2.projection().plot() + p3.projection().plot() Graphics3d Object
It correctly handles various degenerate cases:
sage: Polyhedron(lines=[[1,0,0],[0,1,0],[0,0,1]]).plot() # whole space Graphics3d Object sage: Polyhedron(vertices=[[1,1,1]], rays=[[1,0,0]], ....: lines=[[0,1,0],[0,0,1]]).plot() # half space Graphics3d Object sage: Polyhedron(vertices=[[1,1,1]], ....: lines=[[0,1,0],[0,0,1]]).plot() # R^2 in R^3 Graphics3d Object sage: Polyhedron(rays=[[0,1,0],[0,0,1]], lines=[[1,0,0]]).plot() # quadrant wedge in R^2 Graphics3d Object sage: Polyhedron(rays=[[0,1,0]], lines=[[1,0,0]]).plot() # upper half plane in R^3 Graphics3d Object sage: Polyhedron(lines=[[1,0,0]]).plot() # R^1 in R^2 Graphics3d Object sage: Polyhedron(rays=[[0,1,0]]).plot() # Half-line in R^3 Graphics3d Object sage: Polyhedron(vertices=[[1,1,1]]).plot() # point in R^3 Graphics3d Object
The origin is not included, if it is not in the polyhedron (trac ticket #23555):
sage: Q = Polyhedron([[100],[101]]) sage: P = Q*Q*Q; P A 3-dimensional polyhedron in ZZ^3 defined as the convex hull of 8 vertices sage: p = P.plot() sage: p.bounding_box() ((100.0, 100.0, 100.0), (101.0, 101.0, 101.0))
-
render_fill_2d
(**kwds)¶ Return the filled interior (a polygon) of a polyhedron in 2d.
EXAMPLES:
sage: cps = [i^3 for i in srange(-2,2,1/5)] sage: p = Polyhedron(vertices = [[(t^2-1)/(t^2+1),2*t/(t^2+1)] for t in cps]) sage: proj = p.projection() sage: filled_poly = proj.render_fill_2d() sage: filled_poly.axes_width() 0.8
-
render_line_1d
(**kwds)¶ Return the line of a polyhedron in 1d.
INPUT:
**kwds
– options passed through toline2d()
.
OUTPUT:
A 2-d graphics object.
EXAMPLES:
sage: outline = polytopes.hypercube(1).projection().render_line_1d() sage: outline._objects[0] Line defined by 2 points
-
render_outline_2d
(**kwds)¶ Return the outline (edges) of a polyhedron in 2d.
EXAMPLES:
sage: penta = polytopes.regular_polygon(5) sage: outline = penta.projection().render_outline_2d() sage: outline._objects[0] Line defined by 2 points
-
render_points_1d
(**kwds)¶ Return the points of a polyhedron in 1d.
INPUT:
**kwds
– options passed through topoint2d()
.
OUTPUT:
A 2-d graphics object.
EXAMPLES:
sage: cube1 = polytopes.hypercube(1) sage: proj = cube1.projection() sage: points = proj.render_points_1d() sage: points._objects [Point set defined by 2 point(s)]
-
render_points_2d
(**kwds)¶ Return the points of a polyhedron in 2d.
EXAMPLES:
sage: hex = polytopes.regular_polygon(6) sage: proj = hex.projection() sage: hex_points = proj.render_points_2d() sage: hex_points._objects [Point set defined by 6 point(s)]
-
render_solid_3d
(**kwds)¶ Return solid 3d rendering of a 3d polytope.
EXAMPLES:
sage: p = polytopes.hypercube(3).projection() sage: p_solid = p.render_solid_3d(opacity = .7) sage: type(p_solid) <type 'sage.plot.plot3d.index_face_set.IndexFaceSet'>
-
render_vertices_3d
(**kwds)¶ Return the 3d rendering of the vertices.
EXAMPLES:
sage: p = polytopes.cross_polytope(3) sage: proj = p.projection() sage: verts = proj.render_vertices_3d() sage: verts.bounding_box() ((-1.0, -1.0, -1.0), (1.0, 1.0, 1.0))
-
render_wireframe_3d
(**kwds)¶ Return the 3d wireframe rendering.
EXAMPLES:
sage: cube = polytopes.hypercube(3) sage: cube_proj = cube.projection() sage: wire = cube_proj.render_wireframe_3d() sage: print(wire.tachyon().split('\n')[77]) # for testing FCylinder base -1.0 1.0 -1.0 apex -1.0 -1.0 -1.0 rad 0.005 texture...
-
schlegel
(projection_direction=None, height=1.1)¶ Return the Schlegel projection.
- The polyhedron is translated such that its
center()
is at the origin. - The vertices are then normalized to the unit sphere
- The normalized points are stereographically projected from a point slightly outside of the sphere.
INPUT:
projection_direction
– coordinate list/tuple/iterable orNone
(default). The direction of the Schlegel projection. For a full-dimensional polyhedron, the default is the first facet normal; Otherwise, the vector consisting of the first n primes is chosen.height
– float (default: \(1.1\)). How far outside of the unit sphere the focal point is.
EXAMPLES:
sage: cube4 = polytopes.hypercube(4) sage: from sage.geometry.polyhedron.plot import Projection sage: Projection(cube4).schlegel([1,0,0,0]) The projection of a polyhedron into 3 dimensions sage: _.plot() Graphics3d Object
- The polyhedron is translated such that its
-
stereographic
(projection_point=None)¶ Return the stereographic projection.
INPUT:
projection_point
- The projection point. This must be distinct from the polyhedron’s vertices. Default is \((1,0,\dots,0)\)
EXAMPLES:
sage: from sage.geometry.polyhedron.plot import Projection sage: proj = Projection(polytopes.buckyball()) #long time sage: proj #long time The projection of a polyhedron into 3 dimensions sage: proj.stereographic([5,2,3]).plot() #long time Graphics object consisting of 123 graphics primitives sage: Projection( polytopes.twenty_four_cell() ).stereographic([2,0,0,0]) The projection of a polyhedron into 3 dimensions
-
tikz
(view=[0, 0, 1], angle=0, scale=2, edge_color='blue!95!black', facet_color='blue!95!black', opacity=0.8, vertex_color='green', axis=False)¶ Return a string
tikz_pic
consisting of a tikz picture ofself
according to a projectionview
and an angleangle
obtained via Jmol through the current state property.INPUT:
view
- list (default: [0,0,1]) representing the rotation axis (see note below).angle
- integer (default: 0) angle of rotation in degree from 0 to 360 (see note below).scale
- integer (default: 2) specifying the scaling of the tikz picture.edge_color
- string (default: ‘blue!95!black’) representing colors which tikz recognize.facet_color
- string (default: ‘blue!95!black’) representing colors which tikz recognize.vertex_color
- string (default: ‘green’) representing colors which tikz recognize.opacity
- real number (default: 0.8) between 0 and 1 giving the opacity of the front facets.axis
- Boolean (default: False) draw the axes at the origin or not.
OUTPUT:
- LatexExpr – containing the TikZ picture.
Note
The inputs
view
andangle
can be obtained from the viewer Jmol:1) Right click on the image 2) Select ``Console`` 3) Select the tab ``State`` 4) Scroll to the line ``moveto``
It reads something like:
moveto 0.0 {x y z angle} Scale
The
view
is then [x,y,z] andangle
is angle. The following number is the scale.Jmol performs a rotation of
angle
degrees along the vector [x,y,z] and show the result from the z-axis.EXAMPLES:
sage: P1 = polytopes.small_rhombicuboctahedron() sage: Image1 = P1.projection().tikz([1,3,5], 175, scale=4) sage: type(Image1) <class 'sage.misc.latex.LatexExpr'> sage: print('\n'.join(Image1.splitlines()[:4])) \begin{tikzpicture}% [x={(-0.939161cm, 0.244762cm)}, y={(0.097442cm, -0.482887cm)}, z={(0.329367cm, 0.840780cm)}, sage: _ = open('polytope-tikz1.tex', 'w').write(Image1) # not tested sage: P2 = Polyhedron(vertices=[[1, 1],[1, 2],[2, 1]]) sage: Image2 = P2.projection().tikz(scale=3, edge_color='blue!95!black', facet_color='orange!95!black', opacity=0.4, vertex_color='yellow', axis=True) sage: type(Image2) <class 'sage.misc.latex.LatexExpr'> sage: print('\n'.join(Image2.splitlines()[:4])) \begin{tikzpicture}% [scale=3.000000, back/.style={loosely dotted, thin}, edge/.style={color=blue!95!black, thick}, sage: _ = open('polytope-tikz2.tex', 'w').write(Image2) # not tested sage: P3 = Polyhedron(vertices=[[-1, -1, 2],[-1, 2, -1],[2, -1, -1]]) sage: P3 A 2-dimensional polyhedron in ZZ^3 defined as the convex hull of 3 vertices sage: Image3 = P3.projection().tikz([0.5,-1,-0.1], 55, scale=3, edge_color='blue!95!black',facet_color='orange!95!black', opacity=0.7, vertex_color='yellow', axis=True) sage: print('\n'.join(Image3.splitlines()[:4])) \begin{tikzpicture}% [x={(0.658184cm, -0.242192cm)}, y={(-0.096240cm, 0.912008cm)}, z={(-0.746680cm, -0.331036cm)}, sage: _ = open('polytope-tikz3.tex', 'w').write(Image3) # not tested sage: P=Polyhedron(vertices=[[1,1,0,0],[1,2,0,0],[2,1,0,0],[0,0,1,0],[0,0,0,1]]) sage: P A 4-dimensional polyhedron in ZZ^4 defined as the convex hull of 5 vertices sage: P.projection().tikz() Traceback (most recent call last): ... NotImplementedError: The polytope has to live in 2 or 3 dimensions.
Todo
Make it possible to draw Schlegel diagram for 4-polytopes.
sage: P=Polyhedron(vertices=[[1,1,0,0],[1,2,0,0],[2,1,0,0],[0,0,1,0],[0,0,0,1]]) sage: P A 4-dimensional polyhedron in ZZ^4 defined as the convex hull of 5 vertices sage: P.projection().tikz() Traceback (most recent call last): ... NotImplementedError: The polytope has to live in 2 or 3 dimensions.
Make it possible to draw 3-polytopes living in higher dimension.
-
-
class
sage.geometry.polyhedron.plot.
ProjectionFuncSchlegel
(projection_direction, height=1.1, center=0)¶ The Schlegel projection from the given input point.
EXAMPLES:
sage: from sage.geometry.polyhedron.plot import ProjectionFuncSchlegel sage: proj = ProjectionFuncSchlegel([2,2,2]) sage: proj(vector([1.1,1.1,1.11]))[0] 0.0302...
-
class
sage.geometry.polyhedron.plot.
ProjectionFuncStereographic
(projection_point)¶ The stereographic (or perspective) projection.
EXAMPLES:
sage: from sage.geometry.polyhedron.plot import ProjectionFuncStereographic sage: cube = polytopes.hypercube(3).vertices() sage: proj = ProjectionFuncStereographic([1.2, 3.4, 5.6]) sage: ppoints = [proj(vector(x)) for x in cube] sage: ppoints[0] (-0.0486511..., 0.0859565...)
-
sage.geometry.polyhedron.plot.
cyclic_sort_vertices_2d
(Vlist)¶ Return the vertices/rays in cyclic order if possible.
Note
This works if and only if each vertex/ray is adjacent to exactly two others. For example, any 2-dimensional polyhedron satisfies this.
See
vertex_adjacency_matrix()
for a discussion of “adjacent”.EXAMPLES:
sage: from sage.geometry.polyhedron.plot import cyclic_sort_vertices_2d sage: square = Polyhedron([[1,0],[-1,0],[0,1],[0,-1]]) sage: vertices = [v for v in square.vertex_generator()] sage: vertices [A vertex at (-1, 0), A vertex at (0, -1), A vertex at (0, 1), A vertex at (1, 0)] sage: cyclic_sort_vertices_2d(vertices) [A vertex at (1, 0), A vertex at (0, -1), A vertex at (-1, 0), A vertex at (0, 1)]
Rays are allowed, too:
sage: P = Polyhedron(vertices=[(0, 1), (1, 0), (2, 0), (3, 0), (4, 1)], rays=[(0,1)]) sage: P.adjacency_matrix() [0 1 0 1 0] [1 0 1 0 0] [0 1 0 0 1] [1 0 0 0 1] [0 0 1 1 0] sage: cyclic_sort_vertices_2d(P.Vrepresentation()) [A vertex at (3, 0), A vertex at (1, 0), A vertex at (0, 1), A ray in the direction (0, 1), A vertex at (4, 1)] sage: P = Polyhedron(vertices=[(0, 1), (1, 0), (2, 0), (3, 0), (4, 1)], rays=[(0,1), (1,1)]) sage: P.adjacency_matrix() [0 1 0 0 0] [1 0 1 0 0] [0 1 0 0 1] [0 0 0 0 1] [0 0 1 1 0] sage: cyclic_sort_vertices_2d(P.Vrepresentation()) [A ray in the direction (1, 1), A vertex at (3, 0), A vertex at (1, 0), A vertex at (0, 1), A ray in the direction (0, 1)] sage: P = Polyhedron(vertices=[(1,2)], rays=[(0,1)], lines=[(1,0)]) sage: P.adjacency_matrix() [0 0 1] [0 0 0] [1 0 0] sage: cyclic_sort_vertices_2d(P.Vrepresentation()) [A vertex at (0, 2), A line in the direction (1, 0), A ray in the direction (0, 1)]
-
sage.geometry.polyhedron.plot.
projection_func_identity
(x)¶ The identity projection.
EXAMPLES:
sage: from sage.geometry.polyhedron.plot import projection_func_identity sage: projection_func_identity((1,2,3)) [1, 2, 3]