shape.py
def cube(name, center, rad, shade = 1, rand = False):
    """
    Returns (possibly randomly oriented) cube shape object
    centered at 'center' with radius 'rad'.
    """
    center = np.asarray(center)
    v0 = np.array([ 1,  1,  1]) + center
    v1 = np.array([ 1,  1, -1]) + center
    v2 = np.array([ 1, -1,  1]) + center
    v3 = np.array([ 1, -1, -1]) + center
    v4 = np.array([-1,  1,  1]) + center
    v5 = np.array([-1,  1, -1]) + center
    v6 = np.array([-1, -1,  1]) + center
    v7 = np.array([-1, -1, -1]) + 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}),
                        (4, {'pos': v4}), (5, {'pos': v5}),
                        (6, {'pos': v6}), (7, {'pos': v7})])
    shp.add_edges_from([(0, 1), (0, 2), (0, 4), (1, 3),
                        (1, 5), (2, 3), (2, 6), (3, 7),
                        (4, 6), (4, 5), (5, 7), (6, 7)])
    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) cube shape object
    centered at 'center' with radius 'rad'.
    
Returns (possibly randomly oriented) cube shape object
centered at 'center' with radius 'rad'.
Returns ( possibly randomly oriented ) cube shape object centered at ' center ' with radius ' rad ' .
def cube(name, center, rad, shade = 1, rand = False):
    center = np.asarray(center)
    v0 = np.array([ 1,  1,  1]) + center
    v1 = np.array([ 1,  1, -1]) + center
    v2 = np.array([ 1, -1,  1]) + center
    v3 = np.array([ 1, -1, -1]) + center
    v4 = np.array([-1,  1,  1]) + center
    v5 = np.array([-1,  1, -1]) + center
    v6 = np.array([-1, -1,  1]) + center
    v7 = np.array([-1, -1, -1]) + 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}),
                        (4, {'pos': v4}), (5, {'pos': v5}),
                        (6, {'pos': v6}), (7, {'pos': v7})])
    shp.add_edges_from([(0, 1), (0, 2), (0, 4), (1, 3),
                        (1, 5), (2, 3), (2, 6), (3, 7),
                        (4, 6), (4, 5), (5, 7), (6, 7)])
    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 cube ( name , center , rad , shade = 1 , rand = False ) : center = np . asarray ( center ) v0 = np . array ( [ 1 , 1 , 1 ] ) + center v1 = np . array ( [ 1 , 1 , - 1 ] ) + center v2 = np . array ( [ 1 , - 1 , 1 ] ) + center v3 = np . array ( [ 1 , - 1 , - 1 ] ) + center v4 = np . array ( [ - 1 , 1 , 1 ] ) + center v5 = np . array ( [ - 1 , 1 , - 1 ] ) + center v6 = np . array ( [ - 1 , - 1 , 1 ] ) + center v7 = np . array ( [ - 1 , - 1 , - 1 ] ) + 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 } ) , ( 4 , { 'pos' : v4 } ) , ( 5 , { 'pos' : v5 } ) , ( 6 , { 'pos' : v6 } ) , ( 7 , { 'pos' : v7 } ) ] ) shp . add_edges_from ( [ ( 0 , 1 ) , ( 0 , 2 ) , ( 0 , 4 ) , ( 1 , 3 ) , ( 1 , 5 ) , ( 2 , 3 ) , ( 2 , 6 ) , ( 3 , 7 ) , ( 4 , 6 ) , ( 4 , 5 ) , ( 5 , 7 ) , ( 6 , 7 ) ] ) 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) cube shape object
centered at 'center' with radius 'rad'.
Returns ( possibly randomly oriented ) cube shape object centered at ' center ' with radius ' rad ' .
"""
    Returns (possibly randomly oriented) cube shape object
    centered at 'center' with radius 'rad'.
    """
name
center
rad
shade
rand