def initialize_sphere(target_volume): """ Initialize a sphere with surface area equal to target_volume. """ # Ensure that there's no sphere currently in place. sm.delete_all_geometries() # Build the first tetrahedron build_first_tetrahedron() # Increase set the surface area randomly increase_volume_to_target(target_volume)
def build_torus_from_data(torus_data): """ ONLY USEFUL AT INITIALIZATION. torus_data means two_torus_point_data should be a lists of sets, each with 6 points in it. """ #First we need to check that torus_data is what we want. for t in torus_data: if not (type(t) == tuple and len(t) == 3): raise TypeError("Torus data need to be a list of tuple," + "each of length 2!") for i in t: if not (type(i) == set and len(i) == 2): raise TypeError("The edges must consists of 2 vertices.") for j in i: if not (type(j) == int and j > 0): raise TypeError("The vertices must all be" + "positive integers!") # The vertices in existence will be the union of the triangle # edge tuples. vertex_ids = ut.tuple_of_set_union(torus_data) # The last used vertex id is the maximum of the vertex ids last_used_vertex_id = max(vertex_ids) # Make sure there are no vertices are missing (print torus to # file should not let there be any) assert set(range(1, last_used_vertex_id + 1)) - vertex_ids == set([]) # Once we're sure the set is what we want, we need to make sure no # torus is currently initialized. sm.delete_all_geometries() # Make the points we need sm.make_n_vertices(last_used_vertex_id) # Ensure the points we made are the points in our list assert set(vertex.instances.keys()) == vertex_ids # Make the triangles we need out of the points. tts_triangle_ids = [sm.build_triangle_and_edges(t) for t in torus_data] # Connect all the triangles and tell points what triangles contain them ! connect_all_triangles() return tts_triangle_ids
def build_sphere_from_data(sphere_data): """ sphere_data should be a list of sets, each with 3 points in it. Resets the sphere and then builds it from this data. """ # First we need to check that sphere_data is what we want. for s in sphere_data: if not (type(s) == set and len(s) == 3): raise TypeError("Sphere data needs to be a list of sets, " +"each of length 3!") for i in s: if not (type(i) == int and i > 0): raise TypeError("The vertices must all be " +"positive integers!") # The vertices in existence will be the union of the triangle # point lists: vertex_ids = ut.set_union(sphere_data) # The last used vertex id is the maximum of the vertex ids last_used_vertex_id = max(vertex_ids) # make sure there are no vertices are missing (print sphere to # file shouldn't let there be any) assert set(range(1,last_used_vertex_id+1)) - vertex_ids == set([]) # Once we're sure the set is what we want, we need to make sure no # sphere is currently initialized. sm.delete_all_geometries() # Make the points we need sm.make_n_vertices(last_used_vertex_id) # Ensure the points we made are the points in our list assert set(vertex.instances.keys()) == vertex_ids # Make the triangles we need out of the points. triangle_ids = [sm.build_triangle_and_edges(t) for t in sphere_data] # Connect all the triangles and tell points what triangles contain them connect_all_triangles() return triangle_ids