Esempio n. 1
0
    def render_wireframe_3d(self, **kwds):
        r"""
        Return the 3d wireframe rendering.

        EXAMPLES::

            sage: cube = polytopes.n_cube(3)
            sage: cube_proj = cube.projection()
            sage: wire = cube_proj.render_wireframe_3d()
            sage: print wire.tachyon().split('\n')[76]  # for testing
            FCylinder base -1.0 1.0 -1.0 apex -1.0 -1.0 -1.0 rad 0.005 texture...
        """
        wireframe = []
        for l in self.lines:
            l_coords = self.coordinates_of(l)
            wireframe.append(line3d(l_coords, **kwds))
        for a in self.arrows:
            a_coords = self.coordinates_of(a)
            wireframe.append(arrow3d(a_coords[0], a_coords[1], **kwds))
        return sum(wireframe)
Esempio n. 2
0
    def render_wireframe_3d(self, **kwds):
        r"""
        Return the 3d wireframe rendering.

        EXAMPLES::

            sage: cube = polytopes.n_cube(3)
            sage: cube_proj = cube.projection()
            sage: wire = cube_proj.render_wireframe_3d()
            sage: print wire.tachyon().split('\n')[76]  # for testing
            FCylinder base -1.0 1.0 -1.0 apex -1.0 -1.0 -1.0 rad 0.005 texture...
        """
        wireframe = [];
        for l in self.lines:
            l_coords = self.coordinates_of(l)
            wireframe.append( line3d(l_coords, **kwds))
        for a in self.arrows:
            a_coords = self.coordinates_of(a)
            wireframe.append(arrow3d(a_coords[0], a_coords[1], **kwds))
        return sum(wireframe)
Esempio n. 3
0
File: element.py Progetto: rwst/sage
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
Esempio n. 4
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