@@ -723,6 +723,15 @@ def plot(self, **kwds):
723
723
"""
724
724
Return a plot of the polyhedral complex, if it is of dim at most 3.
725
725
726
+ INPUT:
727
+
728
+ - ``explosion_factor`` -- (default: 0) if positive, separate the cells of
729
+ the complex by extra space. See :func:`exploded_rainbow_plot` for
730
+ additional keyword arguments that can be passed in this case.
731
+
732
+ - other keyword arguments are passed on to
733
+ :meth:`~sage.geometry.polyhedron.base.Polyhedron_base.plot`.
734
+
726
735
EXAMPLES::
727
736
728
737
sage: p1 = Polyhedron(vertices=[(1, 1), (0, 0), (1, 2)])
@@ -733,6 +742,8 @@ def plot(self, **kwds):
733
742
"""
734
743
if self .dimension () > 3 :
735
744
raise ValueError ("cannot plot in high dimension" )
745
+ if kwds .get ('explosion_factor' , 0 ):
746
+ return exploded_rainbow_plot (self .maximal_cell_iterator (), ** kwds )
736
747
return sum (cell .plot (** kwds ) for cell in self .maximal_cell_iterator ())
737
748
738
749
def is_pure (self ):
@@ -2433,3 +2444,79 @@ def cells_list_to_cells_dict(cells_list):
2433
2444
else :
2434
2445
cells_dict [d ] = set ([cell ])
2435
2446
return cells_dict
2447
+
2448
+
2449
+ def exploded_rainbow_plot (polyhedra , * ,
2450
+ center = None , explosion_factor = 1 , sticky_vertices = False ,
2451
+ sticky_center = True , point = None , ** kwds ):
2452
+ r"""
2453
+ Return a plot of several ``polyhedra`` in one figure with extra space between them.
2454
+
2455
+ INPUT:
2456
+
2457
+ - ``polyhedra`` -- an iterable of :class:`~sage.geometry.polyhedron.base.Polyhedron_base` objects
2458
+
2459
+ - keyword arguments: see :meth:`~sage.geometry.polyhedral_complex.PolyhedralComplex.plot`
2460
+
2461
+ EXAMPLES::
2462
+
2463
+ sage: from sage.geometry.polyhedral_complex import exploded_rainbow_plot
2464
+ sage: p1 = Polyhedron(vertices=[(1, 1), (0, 0), (1, 2)])
2465
+ sage: p2 = Polyhedron(vertices=[(1, 2), (0, 0), (0, 2)])
2466
+ sage: p3 = Polyhedron(vertices=[(0, 0), (1, 1), (2, 0)])
2467
+ sage: exploded_rainbow_plot([p1, p2, p3])
2468
+ Graphics object consisting of 20 graphics primitives
2469
+ sage: exploded_rainbow_plot([p1, p2, p3], center=(1, 1))
2470
+ Graphics object consisting of 19 graphics primitives
2471
+ sage: exploded_rainbow_plot([p1, p2, p3], center=(1, 1), sticky_vertices=True)
2472
+ Graphics object consisting of 23 graphics primitives
2473
+ """
2474
+ from sage .plot .colors import rainbow
2475
+ from sage .plot .graphics import Graphics
2476
+ from sage .plot .line import line
2477
+ from sage .plot .point import point as plot_point
2478
+ import itertools
2479
+
2480
+ polyhedra = list (polyhedra )
2481
+ g = Graphics ()
2482
+ if not polyhedra :
2483
+ return g
2484
+ dim = polyhedra [0 ].ambient_dimension ()
2485
+ if center is None :
2486
+ from sage .rings .rational_field import QQ
2487
+ center = vector (QQ , dim )
2488
+ else :
2489
+ center = vector (center )
2490
+ translations = [explosion_factor * (p .center () - center )
2491
+ for p in polyhedra ]
2492
+ vertex_translations_dict = {}
2493
+ for P , t in zip (polyhedra , translations ):
2494
+ for v in P .vertices ():
2495
+ v = v .vector ()
2496
+ v .set_immutable ()
2497
+ vertex_translations_dict [v ] = vertex_translations_dict .get (v , [])
2498
+ vertex_translations_dict [v ].append (v + t )
2499
+ if sticky_vertices or sticky_center :
2500
+ for vertex , vertex_translations in vertex_translations_dict .items ():
2501
+ if vertex == center :
2502
+ if sticky_center :
2503
+ for vt in vertex_translations :
2504
+ g += line ((center , vt ), color = 'gray' )
2505
+ else :
2506
+ if sticky_vertices :
2507
+ for vt1 , vt2 in itertools .combinations (vertex_translations , 2 ):
2508
+ g += line ((vt1 , vt2 ), color = 'gray' )
2509
+
2510
+ if point is None :
2511
+ point = dict (size = 1.5 )
2512
+ if point is not False :
2513
+ vertex_colors_dict = {vertex : color
2514
+ for vertex , color in zip (vertex_translations_dict .keys (),
2515
+ rainbow (len (vertex_translations_dict .keys ())))}
2516
+ for vertex , vertex_translations in vertex_translations_dict .items ():
2517
+ g += plot_point (vertex_translations ,
2518
+ color = vertex_colors_dict [vertex ],
2519
+ alpha = 0.5 , ** point )
2520
+
2521
+ return g + sum ((p + t ).plot (alpha = 0.5 , point = False , color = color , ** kwds )
2522
+ for p , t , color in zip (polyhedra , translations , rainbow (len (polyhedra ))))
0 commit comments