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, [])
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
def crossshape(): gmap = GMap(3) gmap, cube1 = cube(gmap=gmap) gmap, cube2 = cube(gmap=gmap, center=[10, 0, 0]) gmap.sew_dart(cube1[8], cube2[8 * 3 + 1]) gmap, cube3 = cube(gmap=gmap, center=[0, 10, 0]) gmap.sew_dart(cube1[8 * 2], cube3[8 * 4 + 1]) gmap, cube4 = cube(gmap=gmap, center=[0, 0, 10]) gmap.sew_dart(cube1[0], cube4[8 * 5 + 1]) gmap, cube5 = cube(gmap=gmap, center=[-10, 0, 0]) gmap.sew_dart(cube1[8 * 3], cube5[8 + 1]) gmap, cube6 = cube(gmap=gmap, center=[0, -10, 0]) gmap.sew_dart(cube1[8 * 4], cube6[8 * 2 + 1]) gmap, cube7 = cube(gmap=gmap, center=[0, 0, -10]) gmap.sew_dart(cube1[8 * 5], cube7[1]) return gmap, sum([cube1, cube2, cube3, cube4, cube5, cube6, cube7], [])