Ejemplo n.º 1
0
 def plot3d(self, stickers=True):
     """
     ::
     
         sage: C = RubiksCube().move("R*U")
         sage: C.plot3d()
         sage: C.plot()
     """
     while len(self.colors) < 7:
         self.colors.append((.1, .1, .1))
     side_colors = [Texture(color=c, ambient=.75) for c in self.colors]
     start_colors = sum([[c]*8 for c in side_colors], [])
     facets = self._group.facets(self._state)
     facet_colors = [0]*48
     for i in range(48):
         facet_colors[facets[i]-1] = start_colors[i]
     all_colors = side_colors + facet_colors
     pm = [-1,0,1]
     C = sum([self.cubie(.15, .025, x, y, z, all_colors, stickers) for x in pm for y in pm for z in pm], Box(.35, .35, .35, color=self.colors[-1]))
     return C.rotateZ(1.5) #.scale([1,-1,1]).rotateZ(1.5)
Ejemplo n.º 2
0
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