5

I'd like to connect many spheres, by adding a new sphere at some point that's sitting on the surface of a previous sphere. How could we do this?

Suppose I have a unit sphere and a point on it:

myShpere1=Sphere[];
myPoint1=SpherePoints[1];
Graphics3D[{myShpere1, Point[myPoint1]}]

enter image description here

How can we add a second sphere who's surface is touching the previous one at the random point, then a third sphere on a random point of the second sphere, and so on? (for any number of spheres, always choosing a new random point). On a related issue, do spheres have an orientation in MMA, as ellipsoids do? If so, how do we get the "vector/axis" of orientation?

Thanks!

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
TumbiSapichu
  • 1,603
  • 8
  • 17

2 Answers2

5
spheres = Sphere[#, 1] & /@ NestList[
  With[{rp = RandomPoint[Sphere[#, 1]]}, 2 rp - #] &, {0, 0, 0}, 5];

chained spheres

If you need the spheres to be self avoiding, then you could look into this question.

All spheres are oriented upward.

flinty
  • 25,147
  • 2
  • 20
  • 86
  • 1
    You don't need to map Sphere[], since it can support multiple centers if the radius is fixed: Graphics3D[Sphere[NestList[With[{rp = RandomPoint[Sphere[#, 1]]}, 2 rp - #] &, {0, 0, 0}, 5], 1]] – J. M.'s missing motivation Aug 05 '20 at 14:55
4

NestList as in flinty's answer is a bit overkill. You can simply use Accumulate like this:

Graphics3D@Sphere@Accumulate[2 RandomPoint[Sphere[], 5]]

Output

C. E.
  • 70,533
  • 6
  • 140
  • 264
  • Very cool! From @flinty answer I was able to get the coordinates of the points of sphere-sphere contact from the NestList. How could I get this info from your answer? – TumbiSapichu Jul 12 '20 at 00:00
  • 1
    @TumbiSapichu That's a great question for you to figure out, I think, to make sure that you truly understand the solution. It's not difficult. – C. E. Jul 12 '20 at 00:01
  • Ah, I see everything to the right of the accumulate is the points, the rest is just the plotting. I've just never used Accumulate so I though it'd do something weird. Thanks! – TumbiSapichu Jul 12 '20 at 00:03