def triangulation_render_2d(triangulation, **kwds): r""" Return a graphical representation of a 2-d triangulation. INPUT: - ``triangulation`` -- a :class:`Triangulation`. - ``**kwds`` -- keywords that are passed on to the graphics primitives. OUTPUT: A 2-d graphics object. EXAMPLES:: sage: points = PointConfiguration([[0,0],[0,1],[1,0],[1,1],[-1,-1]]) sage: triang = points.triangulate() sage: triang.plot(axes=False, aspect_ratio=1) # indirect doctest Graphics object consisting of 12 graphics primitives """ from sage.plot.all import point2d, line2d, arrow, polygon2d points = [point.reduced_affine() for point in triangulation.point_configuration()] coord = [[p[0], p[1]] for p in points] plot_points = sum([point2d(p, zorder=2, pointsize=10, **kwds) for p in coord]) tmp_lines = [] for t in triangulation: if len(t) >= 2: tmp_lines.append([t[0], t[1]]) if len(t) >= 3: tmp_lines.append([t[0], t[2]]) tmp_lines.append([t[1], t[2]]) all_lines = [] interior_lines = [] for l in tmp_lines: if l not in all_lines: all_lines.append(l) else: interior_lines.append(l) exterior_lines = [l for l in all_lines if not l in interior_lines] plot_interior_lines = sum( [line2d([coord[l[0]], coord[l[1]]], zorder=1, rgbcolor=(0, 1, 0), **kwds) for l in interior_lines] ) plot_exterior_lines = sum( [line2d([coord[l[0]], coord[l[1]]], zorder=1, rgbcolor=(0, 0, 1), **kwds) for l in exterior_lines] ) plot_triangs = sum( [ polygon2d([coord[t[0]], coord[t[1]], coord[t[2]]], zorder=0, rgbcolor=(0.8, 1, 0.8), **kwds) for t in triangulation if len(t) >= 3 ] ) return plot_points + plot_interior_lines + plot_exterior_lines + plot_triangs
def triangulation_render_2d(triangulation, **kwds): r""" Return a graphical representation of a 2-d triangulation. INPUT: - ``triangulation`` -- a :class:`Triangulation`. - ``**kwds`` -- keywords that are passed on to the graphics primitives. OUTPUT: A 2-d graphics object. EXAMPLES:: sage: points = PointConfiguration([[0,0],[0,1],[1,0],[1,1],[-1,-1]]) sage: triang = points.triangulate() sage: triang.plot(axes=False, aspect_ratio=1) # indirect doctest Graphics object consisting of 12 graphics primitives """ from sage.plot.all import point2d, line2d, arrow, polygon2d points = [ point.reduced_affine() for point in triangulation.point_configuration() ] coord = [ [p[0], p[1]] for p in points ] plot_points = sum([ point2d(p, zorder=2, pointsize=10, **kwds) for p in coord ]) tmp_lines = [] for t in triangulation: if len(t)>=2: tmp_lines.append([t[0], t[1]]) if len(t)>=3: tmp_lines.append([t[0], t[2]]) tmp_lines.append([t[1], t[2]]) all_lines = [] interior_lines = [] for l in tmp_lines: if l not in all_lines: all_lines.append(l) else: interior_lines.append(l) exterior_lines = [ l for l in all_lines if not l in interior_lines ] plot_interior_lines = sum([ line2d([ coord[l[0]], coord[l[1]] ], zorder=1, rgbcolor=(0,1,0), **kwds) for l in interior_lines ]) plot_exterior_lines = sum([ line2d([ coord[l[0]], coord[l[1]] ], zorder=1, rgbcolor=(0,0,1), **kwds) for l in exterior_lines ]) plot_triangs = sum([ polygon2d([coord[t[0]], coord[t[1]], coord[t[2]]], zorder=0, rgbcolor=(0.8, 1, 0.8), **kwds) for t in triangulation if len(t)>=3 ]) return \ plot_points + \ plot_interior_lines + plot_exterior_lines + \ plot_triangs
def render_outline_2d(self, **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 """ wireframe = [] for l in self.lines: l_coords = self.coordinates_of(l) wireframe.append(line2d(l_coords, **kwds)) for a in self.arrows: a_coords = self.coordinates_of(a) wireframe.append(arrow(a_coords[0], a_coords[1], **kwds)) return sum(wireframe)
def render_outline_2d(self, **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 """ wireframe = []; for l in self.lines: l_coords = self.coordinates_of(l) wireframe.append( line2d(l_coords, **kwds) ) for a in self.arrows: a_coords = self.coordinates_of(a) wireframe.append( arrow(a_coords[0], a_coords[1], **kwds) ) return sum(wireframe)