コード例 #1
0
def mobiusband(gmap=None):
    from math import pi, cos, sin
    from numpy import array
    nbsq = 16
    if gmap is None: gmap = GMap(2)
    gmap, msquares = toposquares(nbsq, gmap)
    for i in xrange(nbsq - 1):
        gmap.sew_dart(msquares[i][5], msquares[i + 1][0])
    gmap.sew_dart(msquares[nbsq - 1][4], msquares[0][0])

    dalpha = 2 * pi / nbsq
    radius1, radius2 = 10, 5
    length = 1
    alpha = 0
    ralpha = pi / 8
    for sqid in xrange(nbsq):
        dart1, dart2 = msquares[sqid][0], msquares[sqid][1]
        centralpos = array([0, radius1 * cos(alpha), radius2 * sin(alpha)])
        #u,v = [1,0,0], [0,cos(alpha),sin(alpha)]
        #deltapos = [length*cos(alpha), length*sin(alpha)]
        position1 = centralpos + [
            length * cos(ralpha), length * sin(ralpha) * cos(alpha),
            length * sin(ralpha) * sin(alpha)
        ]
        gmap.set_position(dart1, position1)

        position2 = centralpos + [
            length * cos(pi + ralpha), length * sin(pi + ralpha) * cos(alpha),
            length * sin(pi + ralpha) * sin(alpha)
        ]
        gmap.set_position(dart2, position2)
        alpha += dalpha
        ralpha += dalpha / 2

    return gmap, sum(msquares, [])
コード例 #2
0
def gmap_from_triangular_mesh(points, triangles, center=False):
    gmap = GMap()

    triangle_edges = np.sort(
        np.concatenate(
            [np.transpose([v, list(v[1:]) + [v[0]]]) for v in triangles]))

    edges = array_unique(triangle_edges)
    triangle_edges = (vq(triangle_edges, edges)[0]).reshape(
        (len(triangles), 3))

    triangle_edge_vertices = np.concatenate(
        [np.transpose([v, list(v[1:]) + [v[0]]]) for v in triangles])
    triangle_edge_orientation = (triangle_edge_vertices[:, 1] >
                                 triangle_edge_vertices[:, 0]).reshape(
                                     (len(triangles), 3))

    triangle_darts = {}
    for fid, t in enumerate(triangles):
        gmap, tri = topopolygon(3, gmap)
        triangle_darts[fid] = tri

    for eid, e in enumerate(edges):
        fids_to_sew, darts_to_sew = np.where(triangle_edges == eid)
        orientations_to_sew = triangle_edge_orientation[(fids_to_sew,
                                                         darts_to_sew)]
        if len(orientations_to_sew) > 1:
            gmap.sew_dart(
                2,
                triangle_darts[fids_to_sew[0]][2 * darts_to_sew[0] +
                                               (1 - orientations_to_sew[0])],
                triangle_darts[fids_to_sew[1]][2 * darts_to_sew[1] +
                                               (1 - orientations_to_sew[1])])

    mesh_center = np.mean(points, axis=0) if center else np.zeros(3)
    for fid, t in enumerate(triangles):
        for i, p in enumerate(t):
            gmap.set_position(triangle_darts[fid][2 * i],
                              points[p] - mesh_center)

    return gmap