From 583f5469d83289dfb4f85ea6ec3e74224eed3043 Mon Sep 17 00:00:00 2001 From: Yuan Zhou Date: Tue, 11 May 2021 03:44:54 -0400 Subject: [PATCH] revise Projection._init_lines_arrows, take care of rays/lines that are not on a facet, small edits to plotting arguments and docstrings --- src/sage/geometry/polyhedron/base6.py | 31 +++++++++++++++++++++- src/sage/geometry/polyhedron/plot.py | 37 ++++++++++++++++++++++----- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/src/sage/geometry/polyhedron/base6.py b/src/sage/geometry/polyhedron/base6.py index bb9bb520dc7..00768f07b9d 100644 --- a/src/sage/geometry/polyhedron/base6.py +++ b/src/sage/geometry/polyhedron/base6.py @@ -358,6 +358,35 @@ def plot(self, ....: indices = [sp.coord_index_of(vector(x)) for x in vertices] ....: projected_vertices = [sp.transformed_coords[i] for i in indices] ....: assert Polyhedron(projected_vertices).dim() == 2 + + + Check that :trac:`31802` is fixed:: + + sage: halfspace = Polyhedron(rays=[(0, 0, 1)], lines=[(1, 0, 0), (0, 1, 0)]) + sage: len(halfspace.projection().arrows) + 5 + sage: halfspace.plot(fill=(0,1,0)) + Graphics3d Object + sage: fullspace = Polyhedron(lines=[(1, 0, 0), (0, 1, 0), (0, 0, 1)]) + sage: len(fullspace.projection().arrows) + 6 + sage: fullspace.plot(color=(1,0,0), alpha=0.5) + Graphics3d Object + sage: cone = Polyhedron(rays=[(1, 0, 0), (0, 1, 0), (0, 0, 1)]) + sage: cone.plot(fill='rainbow', alpha=0.6) + Graphics3d Object + sage: p = Polyhedron(vertices=[(0,0,0),(1,0,0)],rays=[(-1,1,0),(1,1,0),(0,0,1)]) + sage: p.plot(fill='mediumspringgreen', point='red', size=30, width=2) + Graphics3d Object + + Bug to be fixed:: + + sage: cylinder = Polyhedron(vertices = [(0, 0, 0), (1, 0, 0), (0, 1, 0)], lines=[(0, 0, 1)]) + sage: cylinder.plot(fill='red') # was always black + Graphics3d Object + sage: quarter = Polyhedron(rays = [(-1,0,0),(1,0,0),(0,1,0),(0,0,1)]) + sage: quarter.plot(fill='rainbow') # was all black, now too many colors + Graphics3d Object """ def merge_options(*opts): merged = dict() @@ -435,7 +464,7 @@ def tikz(self, view=[0, 0, 1], angle=0, scale=1, r""" Return a string ``tikz_pic`` consisting of a tikz picture of ``self`` according to a projection ``view`` and an angle ``angle`` - obtained via the threejs viewer. + obtained via the threejs viewer. ``self`` must be bounded. INPUT: diff --git a/src/sage/geometry/polyhedron/plot.py b/src/sage/geometry/polyhedron/plot.py index 901d5204e6e..ec092ca8c24 100644 --- a/src/sage/geometry/polyhedron/plot.py +++ b/src/sage/geometry/polyhedron/plot.py @@ -696,19 +696,40 @@ def _init_lines_arrows(self, polyhedron): sage: p = Polyhedron(ieqs = [[1, 0, 0, 1],[1,1,0,0]]) sage: pp = p.projection() sage: pp.arrows - [[0, 1], [0, 2]] + [[0, 1], [0, 2], [0, 3], [0, 4]] sage: del pp.arrows sage: pp.arrows = Sequence([]) sage: pp._init_lines_arrows(p) sage: pp.arrows - [[0, 1], [0, 2]] + [[0, 1], [0, 2], [0, 3], [0, 4]] + + We check that :trac:`31802` is fixed:: + + sage: x = Polyhedron(lines=[(1, 0, 0),(0, 1, 0)], rays=[(0, 0, 1)]) + sage: y = x.projection() + sage: del y.arrows + sage: y.arrows = Sequence([]) + sage: y._init_lines_arrows(x) + sage: y.arrows + [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5]] """ obj = polyhedron.Vrepresentation() + adj_matrix = polyhedron.vertex_adjacency_matrix() for i in range(len(obj)): if not obj[i].is_vertex(): - continue + if any(adj_matrix[i, j] != 0 + for j in range(len(obj))): + continue + # obj[i] is ray or line + v = polyhedron.vertices()[0].vector() + r = obj[i].vector() + self.arrows.append( [ self.coord_index_of(v), + self.coord_index_of(v + r) ] ) + if obj[i].is_line(): + self.arrows.append( [ self.coord_index_of(v), + self.coord_index_of(v - r) ] ) for j in range(len(obj)): - if polyhedron.vertex_adjacency_matrix()[i, j] == 0: + if adj_matrix[i, j] == 0: continue if i < j and obj[j].is_vertex(): l = [obj[i].vector(), obj[j].vector()] @@ -1107,7 +1128,7 @@ def render_2d(self, point_opts=None, line_opts=None, polygon_opts=None): 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() # optional - sage.plot - Graphics object consisting of 17 graphics primitives + Graphics object consisting of 18 graphics primitives """ plt = Graphics() if point_opts is None: @@ -1186,15 +1207,17 @@ def render_3d(self, point_opts=None, line_opts=None, polygon_opts=None): if polygon_opts is None: polygon_opts = {} if isinstance(point_opts, dict): - point_opts.setdefault('width', 3) + point_opts.setdefault('size', 10) pplt = self.render_vertices_3d(**point_opts) if isinstance(line_opts, dict): - line_opts.setdefault('width', 3) + line_opts.setdefault('width', 1) + # no way to control thickness of line3d lplt = self.render_wireframe_3d(**line_opts) if isinstance(polygon_opts, dict): if 'threejs_flat_shading' not in polygon_opts: polygon_opts['threejs_flat_shading'] = True pgplt = self.render_solid_3d(**polygon_opts) + # zorder is not available return sum(_ for _ in [pplt, lplt, pgplt] if _ is not None) def tikz(self, view=[0, 0, 1], angle=0, scale=1,