Exemplo n.º 1
0
def show(subtriangles=False):
    polygons = []
    facecolors = []
    triangles_indexes = set()

    subtriangle_facecolors = (
        '#CCCCCC',
        '#CCE5FF',
        '#E5FFCC',
        '#FFCCCC',
    )

    if added_sections:
        subtriangles = True

    for p in added_polygons:
        try:
            i = ico.triangles.index(p)
        except ValueError:
            polygons.append(p)
            continue

        if subtriangles:
            sections(range(i * 4, i * 4 + 4))
        else:
            triangles_indexes.add(i)
            polygons.append(p)
            facecolors.append('#DDDDDD')

    for s in added_sections:
        triangles_indexes.add(int(s / 4))
        subtriangle_index = s % 4
        polygons.append(grid.section_triangle(s))
        facecolors.append(subtriangle_facecolors[subtriangle_index])

    ax.add_collection3d(Poly3DCollection(
        polygons,
        facecolors=facecolors,
        edgecolors="#777777",
    ))

    for i in triangles_indexes:
        t = ico.triangles[i]
        mx = my = mz = 0
        for x, y, z in t:
            mx += x
            my += y
            mz += z
        ax.text(mx / 2.6, my / 2.6, mz / 2.6, i, color='#444444')

    if subtriangles:
        ax.legend(
            handles=tuple(
                mpatches.Patch(color=c, label='Sub-triangle #%d' % i)
                for i, c in enumerate(subtriangle_facecolors)
            ),
        )

    plt.show()
        if args.plot:
            plot.polygon(ico.triangles[i])

if args.section:
    sections = []
    for l in args.section:
        sections += l

    for s in sections:
        if 0 > s or s >= 4 * len(ico.triangles):
            print(
                'Section must be in the range [0,%d)' % 4 * len(ico.triangles),
                file=sys.stderr,
            )
            sys.exit(1)
        print(grid.section_triangle(s))
    if args.plot:
        args.plot_subtriangles = True
        plot.sections(sections)

if args.umbrella:
    for pivot in args.umbrella:
        for i, x in enumerate(pivot):
            if x == 'g':
                x = ico.g
            elif x == '-g':
                x = -ico.g
            else:
                try:
                    x = int(x)
                    if x not in (0, -1, 1):
Exemplo n.º 3
0
        if args.plot:
            plot.polygon(ico.triangles[i])

if args.section:
    sections = []
    for l in args.section:
        sections += l

    for s in sections:
        if 0 > s or s >= 4 * len(ico.triangles):
            print(
                'Section must be in the range [0,%d)' % 4 * len(ico.triangles),
                file=sys.stderr,
            )
            sys.exit(1)
        print(grid.section_triangle(s))
    if args.plot:
        args.plot_subtriangles = True
        plot.sections(sections)

if args.umbrella:
    for pivot in args.umbrella:
        for i, x in enumerate(pivot):
            if x == 'g':
                x = ico.g
            elif x == '-g':
                x = -ico.g
            else:
                try:
                    x = int(x)
                    if x not in (0, -1, 1):