Skip to main content
Refined Answer
Source Link
quellenform
  • 39.6k
  • 10
  • 56
  • 149

Since the nodes have evolved a lot over time, there are now more solutions available:

  • For Blender 3.6+ ...just follow this guide
  • For Blender 3.4+ check out @Patter's answer below
  • For Blender 3.1+ use "The shortest edge trick"

...and if you want to get an overview of which node is available in which Blender version, follow this answer: Can't find the node! Which node is available in which Blender version?

Find Nearest Point (Blender 3.6+)

With Blender version 3.6 a new node is available that makes this task a lot easier: Index of Nearest.

In this case, the node simply returns the index of the nearest element, which makes it just as easy to query its position with Sample Index:

enter image description here


(Blender 3.6+)

"The shortest edge trick" (Blender 3.1+)


(Blender 3.1+)

"The shortest edge trick"

Since the nodes have evolved a lot over time, there are now more solutions available:

  • For Blender 3.6+ ...just follow this guide
  • For Blender 3.4+ check out @Patter's answer below
  • For Blender 3.1+ use "The shortest edge trick"

...and if you want to get an overview of which node is available in which Blender version, follow this answer: Can't find the node! Which node is available in which Blender version?

Find Nearest Point (Blender 3.6+)

With Blender version 3.6 a new node is available that makes this task a lot easier: Index of Nearest.

In this case, the node simply returns the index of the nearest element, which makes it just as easy to query its position with Sample Index:

enter image description here


(Blender 3.6+)

"The shortest edge trick" (Blender 3.1+)


(Blender 3.1+)

Refined answer
Source Link
quellenform
  • 39.6k
  • 10
  • 56
  • 149

"The shortest edge trick"

To be honest...that's what I call this technique now.

In contrast to the quadratic complexity approach, I'm nowthis technique offers the advantage that only a little stunned myself at how complicatedfraction of the answer seemed at first, and how simplevertices necessary for the solutioncalculation is in the endcreated, since only a triangulated mesh is used as a basis.

How could I get the distance of a point to its nearest point - Animation 1 So this approach has a clear advantage in terms of speed, especially when the number of points to be calculated is high (500+).

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

How does it work?

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.):

In the case of a grid with slightly offset points, the principle of operation is simplified as follows:

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

If the points are now moved, the edge length changes, which always takes the shortest path due to triangulation:

Here we go: The only necessary basis is therefore to always have an optimally triangulated mesh as a starting point.

Depending on the type of mesh, this can be achieved in different ways.

  • In the case of a sphere you can simply use the node Convex Hull.
  • If you are using a grid with the Distribute Points on Faces node, you can achieve the triangulated mesh with the example I outlined in this answer: Selectively join points using geometry nodes
  • And for other shapes you can use various other tricks.

The rule is simply: if the points are connected at least once over the shortest distance by an edge, then you already have the necessary information.

What is the result?

In this concrete example, the solution applied to a sphere looks like this in the final result:

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

Step by step to the solution

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})$
  • If you get false positive results with this method due to closely spaced points or highly stretched triangles, simply change the scaling. For example, instead of first reducing the length with a factor of $0.5$ and then multiplying by $4$, you can reduce by a factor of $0.8$ and then multiply by $10$.

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

Here we go:

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})$

"The shortest edge trick"

...that's what I call this technique now.

In contrast to the quadratic complexity approach, this technique offers the advantage that only a fraction of the vertices necessary for the calculation is created, since only a triangulated mesh is used as a basis.

So this approach has a clear advantage in terms of speed, especially when the number of points to be calculated is high (500+).

How does it work?

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.):

In the case of a grid with slightly offset points, the principle of operation is simplified as follows:

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

If the points are now moved, the edge length changes, which always takes the shortest path due to triangulation:

The only necessary basis is therefore to always have an optimally triangulated mesh as a starting point.

Depending on the type of mesh, this can be achieved in different ways.

  • In the case of a sphere you can simply use the node Convex Hull.
  • If you are using a grid with the Distribute Points on Faces node, you can achieve the triangulated mesh with the example I outlined in this answer: Selectively join points using geometry nodes
  • And for other shapes you can use various other tricks.

The rule is simply: if the points are connected at least once over the shortest distance by an edge, then you already have the necessary information.

What is the result?

In this concrete example, the solution applied to a sphere looks like this in the final result:

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

Step by step to the solution

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})$
  • If you get false positive results with this method due to closely spaced points or highly stretched triangles, simply change the scaling. For example, instead of first reducing the length with a factor of $0.5$ and then multiplying by $4$, you can reduce by a factor of $0.8$ and then multiply by $10$.
Bounty Ended with 500 reputation awarded by Markus von Broady
Added animated GIF
Source Link
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})$

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

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})$

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})$
Refined answer, added some hints, changed the concept image
Source Link
quellenform
  • 39.6k
  • 10
  • 56
  • 149
Loading
Refined answer
Source Link
quellenform
  • 39.6k
  • 10
  • 56
  • 149
Loading
Refined answer
Source Link
quellenform
  • 39.6k
  • 10
  • 56
  • 149
Loading
Refined answer
Source Link
quellenform
  • 39.6k
  • 10
  • 56
  • 149
Loading
Refined answer, updated blend file
Source Link
quellenform
  • 39.6k
  • 10
  • 56
  • 149
Loading
Refined answer, updated blend file
Source Link
quellenform
  • 39.6k
  • 10
  • 56
  • 149
Loading
Fixed typo
Source Link
quellenform
  • 39.6k
  • 10
  • 56
  • 149
Loading
Source Link
quellenform
  • 39.6k
  • 10
  • 56
  • 149
Loading