def create_unit_sphere(recursion_level=2): """ Creates a unit sphere by subdividing a unit octahedron. Starts with a unit octahedron and subdivides the faces, projecting the resulting points onto the surface of a unit sphere. Parameters ------------ recursion_level : int Level of subdivision, recursion_level=1 will return an octahedron, anything bigger will return a more subdivided sphere. The sphere will have $4^recursion_level+2$ vertices. Returns --------- Sphere : The unit sphere. See Also ---------- create_unit_hemisphere, Sphere """ if recursion_level > 7 or recursion_level < 1: raise ValueError("recursion_level must be between 1 and 7") return unit_octahedron.subdivide(recursion_level - 1)
def test_sphere_subdivide(): sphere1 = unit_octahedron.subdivide(4) sphere2 = Sphere(xyz=sphere1.vertices) nt.assert_equal(sphere1.faces.shape, sphere2.faces.shape) nt.assert_equal(array_to_set(sphere1.faces), array_to_set(sphere2.faces)) sphere1 = unit_icosahedron.subdivide(4) sphere2 = Sphere(xyz=sphere1.vertices) nt.assert_equal(sphere1.faces.shape, sphere2.faces.shape) nt.assert_equal(array_to_set(sphere1.faces), array_to_set(sphere2.faces))
def test_sphere_find_closest(): sphere1 = unit_octahedron.subdivide(4) for ii in range(sphere1.vertices.shape[0]): nt.assert_equal(sphere1.find_closest(sphere1.vertices[ii]), ii)