I need to calculate the distance between two spheres. The outcome of equation should be value determinating speed of moving object (Trying to implement II Kepler's Law). I managed to do something like this, but it doesn't seem to work. I know the equations that I am using are correct because I've checked the simulation in Unity.
-
$\begingroup$ You're calculating the distance of mesh points. The Position node is a field (=position of the mesh points). I don't know how the distance of 2 field inputs is calculated. But the positions of the sphere objects are stored in Object Info->Location. Isn't that what you want? $\endgroup$– BlunderCommented Apr 21, 2022 at 18:49
2 Answers
For a symmetric object like a sphere, by definition, the geometric center is also the center of the object's bounding box. One way to find that center using Geometry Nodes is to add the bounding box minimum and maximum together and divide by two. Once you have the two centers, you can use the Distance math function to determine how far apart they are. Here's an example with two generated spheres:
You can visualize this by using the distance result as one end point of a mesh line:
Here I've set the line to grow on the Z axis as the spheres move apart. If I join the two spheres to the geometry, you can adjust the position of either sphere using its transform node and watch the line grow and shrink as the spheres move farther apart or closer together.
So what you need for Kepler's law is the distance between the centers of two spheres. I have a little bit goofy but working solution:
Basically you scale each sphere to zero, join two of them to one geometry, calculate the bounding box and the distance between the min and max of your bounding box is the distance you're looking for.