shape.py
def triambic_icosahedron(name, center, rad, shade = 1, retain_edges = False, rand = False):
    """
    If retain_edges is True then edges from regular icosahedron are retained.
    """
    c = 2 / (1 + np.sqrt(5))
    n = np.sqrt(1 + c**2)
    v1 =  np.array([ 0,  c, -1]) / n
    v2 =  np.array([ c,  1,  0]) / n
    v3 =  np.array([-c,  1,  0]) / n
    v4 =  np.array([ 0,  c,  1]) / n
    v5 =  np.array([ 0, -c,  1]) / n
    v6 =  np.array([-1,  0,  c]) / n
    v7 =  np.array([ 0, -c, -1]) / n
    v8 =  np.array([ 1,  0, -c]) / n
    v9 =  np.array([ 1,  0,  c]) / n
    v10 = np.array([-1,  0, -c]) / n
    v11 = np.array([ c, -1,  0]) / n
    v12 = np.array([-c, -1,  0]) / n
    shp = shape(name = name, shade = shade, dims = 3)
    shp.add_nodes_from([(1,  {'pos': v1}),  (2,  {'pos': v2}),
                        (3,  {'pos': v3}),  (4,  {'pos': v4}),
                        (5,  {'pos': v5}),  (6,  {'pos': v6}),
                        (7,  {'pos': v7}),  (8,  {'pos': v8}),
                        (9,  {'pos': v9}),  (10, {'pos': v10}),
                        (11, {'pos': v11}), (12, {'pos': v12})])
    faces = [[3, 2, 1],   [2, 3, 4],   [6, 5, 4],   [5, 9, 4],
             [8, 7, 1],   [7, 10, 1],  [12, 11, 5], [11, 12, 7],
             [10, 6, 3],  [6, 10, 12], [9, 8, 2],   [8, 9, 11],
             [3, 6, 4],   [9, 2, 4],   [10, 3, 1],  [2, 8, 1],
             [12, 10, 7], [8, 11, 7],  [6, 12, 5],  [11, 9, 5]]
    for idx, face in enumerate(faces):
        com = np.asarray([np.mean([shp.nodes[pt]["pos"][i] for pt in face]) for i in range(3)])
        new_node = (1 + 2 / np.linalg.norm(com)) * com
        shp.add_nodes_from([(idx + 13, {'pos':new_node})])
        shp.add_edges_from([(idx + 13, pt) for pt in face])
    if retain_edges:
        shp.add_edges_from([(1, 2),  (1, 3),  (1, 7),  (1, 8),   (1, 10),
                            (2, 3),  (2, 4),  (2, 8),  (2, 9),   (3, 4),
                            (3, 6),  (3, 10), (4, 5),  (4, 6),   (4, 9),
                            (5, 6),  (5, 9),  (5, 11), (5, 12),  (6, 10),
                            (6, 12), (7, 8),  (7, 10), (7, 11),  (7, 12),
                            (8, 9),  (8, 11), (9, 11), (10, 12), (11, 12)])
    center = np.asarray(center)
    shp.translate(direction = center)
    com = center_of_mass(shp, dims = 3)
    factor = rad / 3
    shp.scale(factor)
    if rand:
        shp.rotate3d(axis = np.random.rand(3), angle = 2*math.pi*np.random.rand())
    return shp

    If retain_edges is True then edges from regular icosahedron are retained.
    
If retain_edges is True then edges from regular icosahedron are retained.
If retain_edges is True then edges from regular icosahedron are retained .
def triambic_icosahedron(name, center, rad, shade = 1, retain_edges = False, rand = False):
    c = 2 / (1 + np.sqrt(5))
    n = np.sqrt(1 + c**2)
    v1 =  np.array([ 0,  c, -1]) / n
    v2 =  np.array([ c,  1,  0]) / n
    v3 =  np.array([-c,  1,  0]) / n
    v4 =  np.array([ 0,  c,  1]) / n
    v5 =  np.array([ 0, -c,  1]) / n
    v6 =  np.array([-1,  0,  c]) / n
    v7 =  np.array([ 0, -c, -1]) / n
    v8 =  np.array([ 1,  0, -c]) / n
    v9 =  np.array([ 1,  0,  c]) / n
    v10 = np.array([-1,  0, -c]) / n
    v11 = np.array([ c, -1,  0]) / n
    v12 = np.array([-c, -1,  0]) / n
    shp = shape(name = name, shade = shade, dims = 3)
    shp.add_nodes_from([(1,  {'pos': v1}),  (2,  {'pos': v2}),
                        (3,  {'pos': v3}),  (4,  {'pos': v4}),
                        (5,  {'pos': v5}),  (6,  {'pos': v6}),
                        (7,  {'pos': v7}),  (8,  {'pos': v8}),
                        (9,  {'pos': v9}),  (10, {'pos': v10}),
                        (11, {'pos': v11}), (12, {'pos': v12})])
    faces = [[3, 2, 1],   [2, 3, 4],   [6, 5, 4],   [5, 9, 4],
             [8, 7, 1],   [7, 10, 1],  [12, 11, 5], [11, 12, 7],
             [10, 6, 3],  [6, 10, 12], [9, 8, 2],   [8, 9, 11],
             [3, 6, 4],   [9, 2, 4],   [10, 3, 1],  [2, 8, 1],
             [12, 10, 7], [8, 11, 7],  [6, 12, 5],  [11, 9, 5]]
    for idx, face in enumerate(faces):
        com = np.asarray([np.mean([shp.nodes[pt]["pos"][i] for pt in face]) for i in range(3)])
        new_node = (1 + 2 / np.linalg.norm(com)) * com
        shp.add_nodes_from([(idx + 13, {'pos':new_node})])
        shp.add_edges_from([(idx + 13, pt) for pt in face])
    if retain_edges:
        shp.add_edges_from([(1, 2),  (1, 3),  (1, 7),  (1, 8),   (1, 10),
                            (2, 3),  (2, 4),  (2, 8),  (2, 9),   (3, 4),
                            (3, 6),  (3, 10), (4, 5),  (4, 6),   (4, 9),
                            (5, 6),  (5, 9),  (5, 11), (5, 12),  (6, 10),
                            (6, 12), (7, 8),  (7, 10), (7, 11),  (7, 12),
                            (8, 9),  (8, 11), (9, 11), (10, 12), (11, 12)])
    center = np.asarray(center)
    shp.translate(direction = center)
    com = center_of_mass(shp, dims = 3)
    factor = rad / 3
    shp.scale(factor)
    if rand:
        shp.rotate3d(axis = np.random.rand(3), angle = 2*math.pi*np.random.rand())
    return shp
def triambic_icosahedron ( name , center , rad , shade = 1 , retain_edges = False , rand = False ) : c = 2 / ( 1 + np . sqrt ( 5 ) ) n = np . sqrt ( 1 + c ** 2 ) v1 = np . array ( [ 0 , c , - 1 ] ) / n v2 = np . array ( [ c , 1 , 0 ] ) / n v3 = np . array ( [ - c , 1 , 0 ] ) / n v4 = np . array ( [ 0 , c , 1 ] ) / n v5 = np . array ( [ 0 , - c , 1 ] ) / n v6 = np . array ( [ - 1 , 0 , c ] ) / n v7 = np . array ( [ 0 , - c , - 1 ] ) / n v8 = np . array ( [ 1 , 0 , - c ] ) / n v9 = np . array ( [ 1 , 0 , c ] ) / n v10 = np . array ( [ - 1 , 0 , - c ] ) / n v11 = np . array ( [ c , - 1 , 0 ] ) / n v12 = np . array ( [ - c , - 1 , 0 ] ) / n shp = shape ( name = name , shade = shade , dims = 3 ) shp . add_nodes_from ( [ ( 1 , { 'pos' : v1 } ) , ( 2 , { 'pos' : v2 } ) , ( 3 , { 'pos' : v3 } ) , ( 4 , { 'pos' : v4 } ) , ( 5 , { 'pos' : v5 } ) , ( 6 , { 'pos' : v6 } ) , ( 7 , { 'pos' : v7 } ) , ( 8 , { 'pos' : v8 } ) , ( 9 , { 'pos' : v9 } ) , ( 10 , { 'pos' : v10 } ) , ( 11 , { 'pos' : v11 } ) , ( 12 , { 'pos' : v12 } ) ] ) faces = [ [ 3 , 2 , 1 ] , [ 2 , 3 , 4 ] , [ 6 , 5 , 4 ] , [ 5 , 9 , 4 ] , [ 8 , 7 , 1 ] , [ 7 , 10 , 1 ] , [ 12 , 11 , 5 ] , [ 11 , 12 , 7 ] , [ 10 , 6 , 3 ] , [ 6 , 10 , 12 ] , [ 9 , 8 , 2 ] , [ 8 , 9 , 11 ] , [ 3 , 6 , 4 ] , [ 9 , 2 , 4 ] , [ 10 , 3 , 1 ] , [ 2 , 8 , 1 ] , [ 12 , 10 , 7 ] , [ 8 , 11 , 7 ] , [ 6 , 12 , 5 ] , [ 11 , 9 , 5 ] ] for idx , face in enumerate ( faces ) : com = np . asarray ( [ np . mean ( [ shp . nodes [ pt ] [ "pos" ] [ i ] for pt in face ] ) for i in range ( 3 ) ] ) new_node = ( 1 + 2 / np . linalg . norm ( com ) ) * com shp . add_nodes_from ( [ ( idx + 13 , { 'pos' : new_node } ) ] ) shp . add_edges_from ( [ ( idx + 13 , pt ) for pt in face ] ) if retain_edges : shp . add_edges_from ( [ ( 1 , 2 ) , ( 1 , 3 ) , ( 1 , 7 ) , ( 1 , 8 ) , ( 1 , 10 ) , ( 2 , 3 ) , ( 2 , 4 ) , ( 2 , 8 ) , ( 2 , 9 ) , ( 3 , 4 ) , ( 3 , 6 ) , ( 3 , 10 ) , ( 4 , 5 ) , ( 4 , 6 ) , ( 4 , 9 ) , ( 5 , 6 ) , ( 5 , 9 ) , ( 5 , 11 ) , ( 5 , 12 ) , ( 6 , 10 ) , ( 6 , 12 ) , ( 7 , 8 ) , ( 7 , 10 ) , ( 7 , 11 ) , ( 7 , 12 ) , ( 8 , 9 ) , ( 8 , 11 ) , ( 9 , 11 ) , ( 10 , 12 ) , ( 11 , 12 ) ] ) center = np . asarray ( center ) shp . translate ( direction = center ) com = center_of_mass ( shp , dims = 3 ) factor = rad / 3 shp . scale ( factor ) if rand : shp . rotate3d ( axis = np . random . rand ( 3 ) , angle = 2 * math . pi * np . random . rand ( ) ) return shp
If retain_edges is True then edges from regular icosahedron are retained.
If retain_edges is True then edges from regular icosahedron are retained .
"""
    If retain_edges is True then edges from regular icosahedron are retained.
    """
name
center
rad
shade
retain_edges
rand