MCPcopy Create free account
hub / github.com/PyMesh/PyMesh / generate_icosphere

Function generate_icosphere

python/pymesh/meshutils/generate_icosphere.py:9–69  ·  view source on GitHub ↗

Generate icosphere (subdivision surface of a regular `icosahedron`_). Args: radius (``float``): Radius of icosphere. center (``numpy.ndarray``): Sphere center. refinement_order (``int``): (optional) Number of refinement. Returns: The (possibly refined) icos

(radius, center, refinement_order=0)

Source from the content-addressed store, hash-verified

7from .subdivide import subdivide
8
9def generate_icosphere(radius, center, refinement_order=0):
10 """ Generate icosphere (subdivision surface of a regular `icosahedron`_).
11
12 Args:
13 radius (``float``): Radius of icosphere.
14 center (``numpy.ndarray``): Sphere center.
15 refinement_order (``int``): (optional) Number of refinement.
16
17 Returns:
18 The (possibly refined) icosphere :py:class:`Mesh`.
19
20 .. _icosahedron: http://mathworld.wolfram.com/Icosahedron.html
21 """
22 assert(isinstance(radius, Number))
23 assert(len(center) == 3)
24 r = (1.0 + math.sqrt(5.0)) / 2.0
25 vertices = np.array([
26 [-1.0, r, 0.0],
27 [ 1.0, r, 0.0],
28 [-1.0, -r, 0.0],
29 [ 1.0, -r, 0.0],
30 [0.0, -1.0, r],
31 [0.0, 1.0, r],
32 [0.0, -1.0, -r],
33 [0.0, 1.0, -r],
34 [ r, 0.0, -1.0],
35 [ r, 0.0, 1.0],
36 [ -r, 0.0, -1.0],
37 [ -r, 0.0, 1.0],
38 ], dtype=float)
39
40 faces = np.array([
41 [0, 11, 5],
42 [0, 5, 1],
43 [0, 1, 7],
44 [0, 7, 10],
45 [0, 10, 11],
46 [1, 5, 9],
47 [5, 11, 4],
48 [11, 10, 2],
49 [10, 7, 6],
50 [7, 1, 8],
51 [3, 9, 4],
52 [3, 4, 2],
53 [3, 2, 6],
54 [3, 6, 8],
55 [3, 8, 9],
56 [5, 4, 9],
57 [2, 4, 11],
58 [6, 2, 10],
59 [8, 6, 7],
60 [9, 8, 1],
61 ])
62
63 mesh = form_mesh(vertices, faces)
64 mesh = subdivide(mesh, refinement_order)
65
66 length = norm(mesh.vertices, axis=1).reshape((-1, 1))

Callers 7

test_tiny_meshMethod · 0.90
test_simpleMethod · 0.90
test_with_offsetMethod · 0.90
test_sphereMethod · 0.90
test_cut_sphereMethod · 0.90
mainFunction · 0.90

Calls 2

subdivideFunction · 0.90
form_meshFunction · 0.85

Tested by 6

test_tiny_meshMethod · 0.72
test_simpleMethod · 0.72
test_with_offsetMethod · 0.72
test_sphereMethod · 0.72
test_cut_sphereMethod · 0.72