Here is a script to generate a regular icosahedron.
And then you can subdivide each triangle with this algorithm (C# with Vector3
struct):
Vector3[] icoTriangleCorners = new Vector3[3];
public void Subdivide(HashSet<Vector3[]> faces, int subdivision, double radius) {
Vector3 x = (icoTriangleCorners[1] - icoTriangleCorners[0]) / (subdivision + 1);
Vector3 y = (icoTriangleCorners[2] - icoTriangleCorners[1]) / (subdivision + 1);
for(int i = 0; i <= subdivision; ++i) {
for(int j = 0; j <= i; ++j) {
Vector3 a = (icoTriangleCorners[0] + i * x + j * y).normalized * radius;
Vector3 b = (icoTriangleCorners[0] + (i + 1) * x + j * y).normalized * radius;
Vector3 c = (icoTriangleCorners[0] + (i + 1) * x + (j + 1) * y).normalized * radius;
faces.Add(new Vector3[] {a, b, c});
if (i == j) continue;
Vector3 d = (icoTriangleCorners[0] + i * x + (j + 1) * y).normalized * radius;
faces.Add(new Vector3[] {c, d, a});
}
}
}
It generates the new triangle faces with vertices in the same clockwise order.
The vertices of the geodesic sphere are the centroids of the triangles. The centers of the pentagons and hexagons are the corners of the triangles.
You can improve the algorythm by creating a new class for the corners and checking if the Vector3
of the corner has already been created. You can then collect the triangles joining a corner in the corner object. This approach makes the generation of the final faces easier.