def render_3d(projection, **kwds): """ Return 3d rendering of a polyhedron projected into 3-dimensional ambient space. NOTE: This method, ``render_3d``, is used in the ``show()`` method of a polyhedron if it is in 3 dimensions. 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().show() + p2.projection().show() + p3.projection().show() It correctly handles various degenerate cases:: sage: Polyhedron(lines=[[1,0,0],[0,1,0],[0,0,1]]).show() # whole space sage: Polyhedron(vertices=[[1,1,1]], rays=[[1,0,0]], lines=[[0,1,0],[0,0,1]]).show() # half space sage: Polyhedron(vertices=[[1,1,1]], lines=[[0,1,0],[0,0,1]]).show() # R^2 in R^3 sage: Polyhedron(rays=[[0,1,0],[0,0,1]], lines=[[1,0,0]]).show() # quadrant wedge in R^2 sage: Polyhedron(rays=[[0,1,0]], lines=[[1,0,0]]).show() # upper half plane in R^3 sage: Polyhedron(lines=[[1,0,0]]).show() # R^1 in R^2 sage: Polyhedron(rays=[[0,1,0]]).show() # Half-line in R^3 sage: Polyhedron(vertices=[[1,1,1]]).show() # point in R^3 """ if is_Polyhedron(projection): projection = Projection(projection) return \ projection.render_vertices_3d(width=3, color='green', **kwds) +\ projection.render_wireframe_3d(width=3, color='green', **kwds) + \ projection.render_solid_3d(**kwds)
def render_2d(projection, **kwds): """ 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.show() + q2.show() + q3.show() + q4.show() sage: from sage.geometry.polyhedron.plot import render_2d sage: q = render_2d(p1.projection()) sage: q._Graphics__objects [Point set defined by 1 point(s), Arrow from (1.0,1.0) to (2.0,2.0), Polygon defined by 3 points] """ if is_Polyhedron(projection): projection = Projection(projection) return \ projection.render_points_2d(zorder=2, pointsize=10, **kwds) + \ projection.render_outline_2d(zorder=1, **kwds) + \ projection.render_fill_2d(zorder=0, rgbcolor=(0,1,0), **kwds)
def render_3d(projection, point_opts={}, line_opts={}, polygon_opts={}): """ Return 3d rendering of a polyhedron projected into 3-dimensional ambient space. NOTE: This method, ``render_3d``, is used in the ``show()`` method of a polyhedron if it is in 3 dimensions. 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().show() + p2.projection().show() + p3.projection().show() It correctly handles various degenerate cases:: sage: Polyhedron(lines=[[1,0,0],[0,1,0],[0,0,1]]).show() # whole space sage: Polyhedron(vertices=[[1,1,1]], rays=[[1,0,0]], lines=[[0,1,0],[0,0,1]]).show() # half space sage: Polyhedron(vertices=[[1,1,1]], lines=[[0,1,0],[0,0,1]]).show() # R^2 in R^3 sage: Polyhedron(rays=[[0,1,0],[0,0,1]], lines=[[1,0,0]]).show() # quadrant wedge in R^2 sage: Polyhedron(rays=[[0,1,0]], lines=[[1,0,0]]).show() # upper half plane in R^3 sage: Polyhedron(lines=[[1,0,0]]).show() # R^1 in R^2 sage: Polyhedron(rays=[[0,1,0]]).show() # Half-line in R^3 sage: Polyhedron(vertices=[[1,1,1]]).show() # point in R^3 """ if is_Polyhedron(projection): projection = Projection(projection) from sage.plot.plot3d.base import Graphics3d plt = Graphics3d() if isinstance(point_opts, dict): point_opts.setdefault('width', 3) plt += projection.render_vertices_3d(**point_opts) if isinstance(line_opts, dict): line_opts.setdefault('width', 3) plt += projection.render_wireframe_3d(**line_opts) if isinstance(polygon_opts, dict): plt += projection.render_solid_3d(**polygon_opts) return plt
def render_2d(projection, 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.show() + q2.show() + q3.show() + q4.show() sage: from sage.geometry.polyhedron.plot import render_2d sage: q = render_2d(p1.projection()) sage: q._objects [Point set defined by 1 point(s), Arrow from (1.0,1.0) to (2.0,2.0), Polygon defined by 3 points] """ if is_Polyhedron(projection): projection = Projection(projection) from sage.plot.graphics import Graphics plt = Graphics() if isinstance(point_opts, dict): point_opts.setdefault('zorder', 2) point_opts.setdefault('pointsize', 10) plt += projection.render_points_2d(**point_opts) if isinstance(line_opts, dict): line_opts.setdefault('zorder', 1) plt += projection.render_outline_2d(**line_opts) if isinstance(polygon_opts, dict): polygon_opts.setdefault('zorder', 0) plt += projection.render_fill_2d(**polygon_opts) return plt