# How to make a 3D square pyramid with spheres?

jospercomp shared this question 6 months ago

How to make a 3D square pyramid with spheres with a slider?  2

You asked a similar thing two weeks ago. The solution I posted had a slider for the number of levels.

Edit: Oh wait, those were triangular pyramids back then. Maybe I'll modify that to a 4-sided pyramid later. Or maybe you can figure out the proper formula yourself. 1

MidPoints=Flatten(Sequence(Sequence(Sequence((2r k - r j, 2r m - r j, 2sqrt(2) / sqrt(3) r (n - 1 - j)), m, 0, j), k, 0, j), j, 0, n - 1))

Zip(Sphere(P, r), P, MidPoints) 2

Almost. You adjusted the x and y coordinates, but not the z coordinate, so now the levels hang a bit in the air (i.e. the spheres of the higher level don't touch the ones in level below). Just change the "2sqrt(2)/sqrt(3)" in the z coordinate to only "sqrt(2)". 1

MidPoints=Flatten(Sequence(Sequence(Sequence((2r k - r j, 2r m - r j, r + sqrt(2) / r (n - 1 - j)), m, 0, j), k, 0, j), j, 0, n - 1))

Zip(Sphere(P, r), P, MidPoints) 