A latitude and longitude grid squeezes every row into a point at the poles. A cube offers six square grids with no poles at all: build them, push them outward onto a sphere, and join them. This lesson pairs with [Unity] Procedural Planets (E01 the sphere) and Coding Adventure: Procedural Moons and Planets by Sebastian Lague, linked under Watch & read. You build the face frames, two sphere mappings, a closed planet mesh with outward winding, a crater profile and a measure of how uneven the triangles are.
A face is named by its normal, one of the six axis directions. Two more vectors, a and b, span the face, and (normal, a, b) must be right-handed: normal × a = b, which gives a × b = normal. Take a as a cyclic shift of the normal, (n₁, n₂, n₀), and get b from the cross product. That recipe is right-handed on all six faces, including the three with a negative normal. A triangle that steps along a and then along b is counter-clockwise seen from outside only when a × b points outward.
A grid point is normal + s·a + t·b with s and t running from -1 to 1 in n steps. For the top face, normal = (0, 0, 1) gives a = (0, 1, 0) and b = (-1, 0, 0). With n = 3 the middle point is (0, 0, 1) and the corner at index [0, 0] is (0, 0, 1) - a - b = (1, -1, 1).
Neighbouring faces share their border, so six grids of n × n points are not six disjoint sets. The 8 cube corners are each listed three times and the n - 2 inner points of each of the 12 edges twice, which leaves 6n² - 12n + 8 distinct points. For n = 4 that is 96 listed and 56 real. Merge them by exact integer cube coordinates (steps of 2i - (n - 1)), not by rounding positions after the mapping, and apply the height function after merging, so a seam point gets exactly one radius.
import numpy as np
n = 4
points = []
for f in [(1, 0, 0), (-1, 0, 0), (0, 1, 0), (0, -1, 0), (0, 0, 1), (0, 0, -1)]:
f = np.array(f)
a = np.roll(f, -1)
b = np.cross(f, a)
t = 2 * np.arange(n) - (n - 1)
grid = (n - 1) * f + t[:, None, None] * a + t[None, :, None] * b
points.append(grid.reshape(-1, 3))
points = np.concatenate(points)
print(len(points), len(np.unique(points, axis=0)), 6 * n * n - 12 * n + 8)A closed surface without holes has V - E + F = 2, where V, E and F count vertices, edges and triangles. Each triangle has three edges and each edge belongs to two triangles, so E = 3F / 2. For n = 3 the mesh has V = 26 and F = 48, hence E = 72 and 26 - 72 + 48 = 2. A duplicated seam breaks this count.
Pushing a cube point radially onto the sphere means dividing it by its length. It makes the cells uneven. The second mapping multiplies each coordinate by a square root, x·√(1 - y²/2 - z²/2 + y²z²/3), and likewise for y and z. It still lands on the unit sphere and it spreads the area more evenly. Measure unevenness as the largest triangle area divided by the smallest.
import numpy as np
t = np.linspace(-1, 1, 9)
row = np.stack([np.zeros(9), t, np.ones(9)], axis=1) # a line through the middle of the top face
x2, y2, z2 = (row ** 2).T
factor = np.stack([np.sqrt(1 - y2 / 2 - z2 / 2 + y2 * z2 / 3),
np.sqrt(1 - z2 / 2 - x2 / 2 + z2 * x2 / 3),
np.sqrt(1 - x2 / 2 - y2 / 2 + x2 * y2 / 3)], axis=1)
for u in (row / np.linalg.norm(row, axis=1, keepdims=True), row * factor):
degrees = np.degrees(np.arccos((u[:-1] * u[1:]).sum(axis=1)))
print(degrees.round(2).tolist())The first line is the plain mapping: steps of 8.13° at the edge grow to 14.04° in the middle. The second is the evening formula: 12.97° to 10.18°. It does not make every step equal, but it lowers the area ratio of the whole mesh, as the chart shows. At n = 2 and n = 3 both mappings agree, because every grid point is a corner, an edge midpoint or a face centre.
A crater is a height offset that depends only on the distance from its centre. With t = distance / radius, take -depth + (depth + rim)·t² inside the crater, which starts at -depth in the middle and reaches rim at the wall, and rim·(2 - t)² for 1 < t < 2, which falls from the rim crest back to flat ground. Beyond t = 2 the offset is 0. On a planet use the angle between a vertex and the crater's centre as the distance and 1 + crater(...) as the radius.
import numpy as np
t = np.array([0.0, 1.0, 2.0, 3.0, 4.0]) / 2 # distances 0..4 for radius 2
bowl = -0.5 + (0.5 + 0.1) * t * t # depth 0.5, rim 0.1
wall = 0.1 * np.clip(2 - t, 0, 1) ** 2
print(np.where(t <= 1, bowl, wall).round(3).tolist())Mistakes come in two kinds. The first is leaving seam points duplicated, for instance by never merging, or by rounding positions that two faces computed in slightly different ways. Relief then opens cracks, because the two copies can take different radii. The second is a frame that is orthonormal but left-handed on some faces: b taken as a second cyclic shift is right on the three negative faces and mirrored on the other three. Those faces are wound inward and vanish under back-face culling, so check all six.
The hidden tests check the vertex and triangle counts, V - E + F = 2, that every directed edge is used once and every undirected edge twice, unit length for both mappings, a positive signed volume close to 4π/3 (about 0.1% low at n = 32, because flat triangles sit inside the sphere) and a brute-force comparison of every face point against the merged mesh. They also use a smooth and a wild height function. These checks show that the surface is closed and faces outward. They do not show that it looks like a planet: the area ratio only says how uneven the cells are, and nothing here measures how convincing the relief is.