shape.py
def tetrahedron(name, center, rad, shade = 1, rand = False):
    """
    Returns (possibly randomly oriented) tetrahedron shape object
    centered at 'center' with radius 'rad'.
    """
    a = 1/3
    b = np.sqrt(8/9)
    c = np.sqrt(2/9)
    d = np.sqrt(2/3)
    center = np.asarray(center)
    v0 = np.array([0,   0,  1]) + center
    v1 = np.array([-c,  d, -a]) + center
    v2 = np.array([-c, -d, -a]) + center
    v3 = np.array([b,   0, -a]) + center
    shp = shape(name = name, shade = shade, dims = 3)
    shp.add_nodes_from([(0, {'pos': v0}), (1, {'pos': v1}),
                        (2, {'pos': v2}), (3, {'pos': v3})])
    shp.add_edges_from([(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)])
    com = center_of_mass(shp, dims = 3)
    factor = rad / np.linalg.norm(v0 - com)
    shp.scale(factor)
    if rand:
        shp.rotate3d(axis = np.random.rand(3), angle = 2*math.pi*np.random.rand())
    return shp

    Returns (possibly randomly oriented) tetrahedron shape object
    centered at 'center' with radius 'rad'.
    
Returns (possibly randomly oriented) tetrahedron shape object
centered at 'center' with radius 'rad'.
Returns ( possibly randomly oriented ) tetrahedron shape object centered at ' center ' with radius ' rad ' .
def tetrahedron(name, center, rad, shade = 1, rand = False):
    a = 1/3
    b = np.sqrt(8/9)
    c = np.sqrt(2/9)
    d = np.sqrt(2/3)
    center = np.asarray(center)
    v0 = np.array([0,   0,  1]) + center
    v1 = np.array([-c,  d, -a]) + center
    v2 = np.array([-c, -d, -a]) + center
    v3 = np.array([b,   0, -a]) + center
    shp = shape(name = name, shade = shade, dims = 3)
    shp.add_nodes_from([(0, {'pos': v0}), (1, {'pos': v1}),
                        (2, {'pos': v2}), (3, {'pos': v3})])
    shp.add_edges_from([(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)])
    com = center_of_mass(shp, dims = 3)
    factor = rad / np.linalg.norm(v0 - com)
    shp.scale(factor)
    if rand:
        shp.rotate3d(axis = np.random.rand(3), angle = 2*math.pi*np.random.rand())
    return shp
def tetrahedron ( name , center , rad , shade = 1 , rand = False ) : a = 1 / 3 b = np . sqrt ( 8 / 9 ) c = np . sqrt ( 2 / 9 ) d = np . sqrt ( 2 / 3 ) center = np . asarray ( center ) v0 = np . array ( [ 0 , 0 , 1 ] ) + center v1 = np . array ( [ - c , d , - a ] ) + center v2 = np . array ( [ - c , - d , - a ] ) + center v3 = np . array ( [ b , 0 , - a ] ) + center shp = shape ( name = name , shade = shade , dims = 3 ) shp . add_nodes_from ( [ ( 0 , { 'pos' : v0 } ) , ( 1 , { 'pos' : v1 } ) , ( 2 , { 'pos' : v2 } ) , ( 3 , { 'pos' : v3 } ) ] ) shp . add_edges_from ( [ ( 0 , 1 ) , ( 0 , 2 ) , ( 0 , 3 ) , ( 1 , 2 ) , ( 1 , 3 ) , ( 2 , 3 ) ] ) com = center_of_mass ( shp , dims = 3 ) factor = rad / np . linalg . norm ( v0 - com ) shp . scale ( factor ) if rand : shp . rotate3d ( axis = np . random . rand ( 3 ) , angle = 2 * math . pi * np . random . rand ( ) ) return shp
Returns (possibly randomly oriented) tetrahedron shape object
centered at 'center' with radius 'rad'.
Returns ( possibly randomly oriented ) tetrahedron shape object centered at ' center ' with radius ' rad ' .
"""
    Returns (possibly randomly oriented) tetrahedron shape object
    centered at 'center' with radius 'rad'.
    """
name
center
rad
shade
rand