5
$\begingroup$

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!

$\endgroup$

2 Answers 2

5
$\begingroup$
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.

$\endgroup$
1
  • 1
    $\begingroup$ 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]] $\endgroup$ Aug 5, 2020 at 14:55
4
$\begingroup$

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

$\endgroup$
3
  • $\begingroup$ 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? $\endgroup$ Jul 12, 2020 at 0:00
  • 1
    $\begingroup$ @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. $\endgroup$
    – C. E.
    Jul 12, 2020 at 0:01
  • $\begingroup$ 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! $\endgroup$ Jul 12, 2020 at 0:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.