Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
revise Projection._init_lines_arrows, take care of rays/lines that ar…
Browse files Browse the repository at this point in the history
…e not on a facet, small edits to plotting arguments and docstrings
  • Loading branch information
yuan-zhou authored and mkoeppe committed Apr 2, 2022
1 parent 82b4464 commit 583f546
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 8 deletions.
31 changes: 30 additions & 1 deletion src/sage/geometry/polyhedron/base6.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
37 changes: 30 additions & 7 deletions src/sage/geometry/polyhedron/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 583f546

Please sign in to comment.