def render_vertices_3d(self, **kwds): """ Return the 3d rendering of the vertices. EXAMPLES:: sage: p = polytopes.cross_polytope(3) sage: proj = p.projection() sage: verts = proj.render_vertices_3d() sage: verts.bounding_box() ((-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)) """ return point3d(self.coordinates_of(self.points), **kwds)
def triangulation_render_3d(triangulation, **kwds): r""" Return a graphical representation of a 3-d triangulation. INPUT: - ``triangulation`` -- a :class:`Triangulation`. - ``**kwds`` -- keywords that are passed on to the graphics primitives. OUTPUT: A 3-d graphics object. EXAMPLES:: sage: p = [[0,-1,-1],[0,0,1],[0,1,0], [1,-1,-1],[1,0,1],[1,1,0]] sage: points = PointConfiguration(p) sage: triang = points.triangulate() sage: triang.plot(axes=False) # indirect doctest Graphics3d Object """ from sage.plot.plot3d.all import point3d, line3d, arrow3d, polygon3d points = [point.reduced_affine() for point in triangulation.point_configuration()] coord = [[p[0], p[1], p[2]] for p in points] plot_points = sum([point3d(p, size=15, **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]]) if len(t) >= 4: tmp_lines.append([t[0], t[3]]) tmp_lines.append([t[1], t[3]]) tmp_lines.append([t[2], t[3]]) 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] from sage.plot.plot3d.texture import Texture line_int = Texture(color="darkblue", ambient=1, diffuse=0) line_ext = Texture(color="green", ambient=1, diffuse=0) triang_int = Texture(opacity=0.3, specular=0, shininess=0, diffuse=0, ambient=1, color="yellow") triang_ext = Texture(opacity=0.6, specular=0, shininess=0, diffuse=0, ambient=1, color="green") plot_interior_lines = sum( [line3d([coord[l[0]], coord[l[1]]], thickness=2, texture=line_int, **kwds) for l in interior_lines] ) plot_exterior_lines = sum( [line3d([coord[l[0]], coord[l[1]]], thickness=3, texture=line_ext, **kwds) for l in exterior_lines] ) tmp_triangs = [] for t in triangulation: if len(t) >= 3: tmp_triangs.append([t[0], t[1], t[2]]) if len(t) >= 4: tmp_triangs.append([t[0], t[1], t[3]]) tmp_triangs.append([t[0], t[2], t[3]]) tmp_triangs.append([t[1], t[2], t[3]]) all_triangs = [] interior_triangs = [] for l in tmp_triangs: if l not in all_triangs: all_triangs.append(l) else: interior_triangs.append(l) exterior_triangs = [l for l in all_triangs if not l in interior_triangs] plot_interior_triangs = sum( [polygon3d([coord[t[0]], coord[t[1]], coord[t[2]]], texture=triang_int, **kwds) for t in interior_triangs] ) plot_exterior_triangs = sum( [polygon3d([coord[t[0]], coord[t[1]], coord[t[2]]], texture=triang_ext, **kwds) for t in exterior_triangs] ) return plot_points + plot_interior_lines + plot_exterior_lines + plot_interior_triangs + plot_exterior_triangs
def triangulation_render_3d(triangulation, **kwds): r""" Return a graphical representation of a 3-d triangulation. INPUT: - ``triangulation`` -- a :class:`Triangulation`. - ``**kwds`` -- keywords that are passed on to the graphics primitives. OUTPUT: A 3-d graphics object. EXAMPLES:: sage: p = [[0,-1,-1],[0,0,1],[0,1,0], [1,-1,-1],[1,0,1],[1,1,0]] sage: points = PointConfiguration(p) sage: triang = points.triangulate() sage: triang.plot(axes=False) # indirect doctest Graphics3d Object """ from sage.plot.plot3d.all import point3d, line3d, polygon3d points = [ point.reduced_affine() for point in triangulation.point_configuration() ] coord = [[p[0], p[1], p[2]] for p in points] plot_points = sum([point3d(p, size=15, **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]]) if len(t) >= 4: tmp_lines.append([t[0], t[3]]) tmp_lines.append([t[1], t[3]]) tmp_lines.append([t[2], t[3]]) 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] from sage.plot.plot3d.texture import Texture line_int = Texture(color='darkblue', ambient=1, diffuse=0) line_ext = Texture(color='green', ambient=1, diffuse=0) triang_int = Texture(opacity=0.3, specular=0, shininess=0, diffuse=0, ambient=1, color='yellow') triang_ext = Texture(opacity=0.6, specular=0, shininess=0, diffuse=0, ambient=1, color='green') plot_interior_lines = sum([ line3d([coord[l[0]], coord[l[1]]], thickness=2, texture=line_int, **kwds) for l in interior_lines ]) plot_exterior_lines = sum([ line3d([coord[l[0]], coord[l[1]]], thickness=3, texture=line_ext, **kwds) for l in exterior_lines ]) tmp_triangs = [] for t in triangulation: if len(t) >= 3: tmp_triangs.append([t[0], t[1], t[2]]) if len(t) >= 4: tmp_triangs.append([t[0], t[1], t[3]]) tmp_triangs.append([t[0], t[2], t[3]]) tmp_triangs.append([t[1], t[2], t[3]]) all_triangs = [] interior_triangs = [] for l in tmp_triangs: if l not in all_triangs: all_triangs.append(l) else: interior_triangs.append(l) exterior_triangs = [l for l in all_triangs if not l in interior_triangs] plot_interior_triangs = \ sum([ polygon3d([coord[t[0]], coord[t[1]], coord[t[2]]], texture = triang_int, **kwds) for t in interior_triangs ]) plot_exterior_triangs = \ sum([ polygon3d([coord[t[0]], coord[t[1]], coord[t[2]]], texture = triang_ext, **kwds) for t in exterior_triangs ]) return \ plot_points + \ plot_interior_lines + plot_exterior_lines + \ plot_interior_triangs + plot_exterior_triangs