Metadata
aliases: []
shorthands: {}
created: 2022-02-27 23:00:20
modified: 2022-05-21 21:25:57
A good way of generating a sphere mesh is to start out from a regular shape
The result of the method is shown by the following figure with
The ratio of areas between the largest and smallest triangle on the mesh:
The example codes are written in Python and use the separate arrays convention for storing triangle meshes.
This function, generate_icosahedron just gives a hardcoded icosahedron mesh:
def generate_icosahedron(r = 1):
X=.525731112119133606
Z=.850650808352039932
N=0.0
x = [-X, X, -X, X, N, N, N, N, Z, -Z, Z, -Z]
y = [N, N, N, N, Z, Z, -Z, -Z, X, X, -X, -X]
z = [Z, Z, -Z, -Z, X, -X, X, -X, N, N, N, N]
for n in range(len(x)):
x[n] = x[n]*r
y[n] = y[n]*r
z[n] = z[n]*r
i = [0, 0, 9, 4, 4, 8, 8, 5, 5, 2, 7, 7, 7, 11, 0, 6, 9, 9, 9, 7]
j = [4, 9, 5, 5, 8, 10, 3, 3, 2, 7, 10, 6, 11, 0, 1, 1, 0, 11, 2, 2]
k = [1, 4, 4, 8, 1, 1, 10, 8, 3, 3, 3, 10, 6, 6, 6, 10, 11, 2, 5, 11]
return x, y, z, i, j, k
The result of this is this icosahedron:
Then with the shown function and the subdivide_triangles function from here, we can give the mesh extra vertices. Finally, by projecting these vertices to a sphere, we get the final result.
x, y, z, i, j, k = generate_icosahedron(1)
x, y, z, i, j, k = subdivide_triangles(x, y, z, i, j, k, 4)
for n in range(len(x)):
R = np.sqrt(x[n]**2 + y[n]**2 + z[n]**2)
x[n] = x[n]/R
y[n] = y[n]/R
z[n] = z[n]/R
So the final result is the first figure on the page.