Skip to main content
9 of 11
Added animated GIF
quellenform
  • 39.6k
  • 10
  • 56
  • 149

To be honest, I'm now a little stunned myself at how complicated the answer seemed at first, and how simple the solution is in the end.

How could I get the distance of a point to its nearest point - Animation 1

How could I get the distance of a point to its nearest point - Animation 2

The basic idea here is to shorten all edges between the points proportionally, and thus find the closest point. This method saves a lot of calculations and complexity and is basically applicable to any shape (grid, sphere, cube, etc.):

How could I get the distance of a point to its nearest point - Concept

How could I get the distance of a point to its nearest point - Concept Animation

Here we go:

  1. First create your points with Distribute Points on Faces.

    How could I get the distance of a point to its nearest point - Step 1

  2. In the case of a sphere, the Convex Hull node makes it easy to obtain the required triangulated mesh without missing a point. For other shapes, it is best to create the mesh using the Triangulate (Shortest Diagonal) node.

    How could I get the distance of a point to its nearest point - Step 2

  3. Using the nodes Extrude Mesh, Split Edges and Separate Geometry you get the isolated edges of this mesh.

    How could I get the distance of a point to its nearest point - Step 3

  4. Then reduce the scale of each edge by half.

    How could I get the distance of a point to its nearest point - Step 4

  5. Now that the edges are reduced in proportion to their length, you can reliably find the nearest point with the node Geometry Proximity. If you then calculate the direction vector between your originally created points and the position results of Geometry Proximity, you will know in which direction the shortest vector points.

    How could I get the distance of a point to its nearest point - Step 5

  6. In the last step you only have to correct the length. Since you have shortened the edges by 50% before, you simply scale the direction vector by $4$, which is exactly the point you were looking for (Apart from a few minor rounding errors).

    How could I get the distance of a point to its nearest point - Step

The final result is this (Each previously created point is here connected to the nearest point):

How could I get the distance of a point to its nearest point - Result

...and with animated Seed/Density it looks like this:

How could I get the distance of a point to its nearest point - Animation 3

Here is an overview of the node group:

How could I get the distance of a point to its nearest point - Node Group

Here is the blend file (I added an additional view for debugging):

...and as a bonus I added the animation to the blend file too, because it's so nice to see the thing in motion (even though I won't win any beauty contests with the node tree, but it's meant as a little animation example).

Useful Hints

  • This solution works best by converting a mesh into triangles with the shortest edge length! Quads are less suitable here, because they may produce false positives.
  • If you do not use a sphere, it is best to create the mesh using the Triangulate (Shortest Diagonal) node.
  • If you use a sphere, this works best with a sphere of the type Ico Sphere in a higher resolution.
  • Remember: If you use a sphere like in this example, the calculated distance is of course also the shortest straight path between the points. The real distance on a sphere would actually be the angle between the points multiplied by the radius of the sphere. The angle is obtained with the formula: $\alpha = 2 \ast \arcsin (\frac {s}{r \ast 2})$
quellenform
  • 39.6k
  • 10
  • 56
  • 149