2

I can find a first nearest point. How can I find a second nearest point?

PS: The screenshot is from Blender 3.2. Feel free to use any Blender version.

enter image description here

mifth
  • 2,341
  • 28
  • 36
  • No time to try it, but just an idea: maybe there's a way with the Delete Geometry node... find the nearest, delete it and find the nearest in the reduced geometry... that should be the second nearest. Of course you must somehow preserve the original points and their indices... – Gordon Brinkmann Nov 24 '22 at 10:22
  • Although depending on how you implement that it could be problematic, because for one point the second nearest might be one first nearest of a different point but then it's gone... maybe there's a way of feeding the distance to nearest into a math node set to greater than and then find the nearest which has a larger distance, that should be second nearest too. – Gordon Brinkmann Nov 24 '22 at 10:27
  • 2
    The only way to do this is sorting: for each point you need to find a list of points sorted by distance to that point - and pick the 2nd. How can I re-sort the points/indexes of an object in geometry nodes? – Markus von Broady Nov 24 '22 at 12:02
  • Personally, I find the two suggestions from MarkusvonBroady and GordonBrinkman very useful and both should actually work. However, I would prefer the sorting suggested by @MarkusvonBroady. – quellenform Nov 24 '22 at 18:31
  • After reading through the question again, I realize that we may have all misunderstood you: In order to find the second closest point, we would first have to know from which point you actually want to find the second closest point. Therefore the question: Where is the reference point? Is it variable? Is the starting point always the current point? Please be so kind and explain this a little more precisely. Thank you! – quellenform Nov 26 '22 at 13:35
  • 1
    @quellenform speak for yourself, I understood in his screenshot for each point coming from "Distribute Points", he is finding the nearest point from "Grid" node, so I'm pretty sure he wants to find 2nd nearest point for each point. Since TA doesn't have an option to find 2nd nearest, you need to remove 1st nearest for it to find the 2nd nearest, but since 1st nearest is potentially different for each point… You would have to duplicate the geometry as many times as many points it has… Very similar to my quadratic sorting, which as I understand is obsolete now. – Markus von Broady Nov 26 '22 at 14:32
  • However, in this special case you can solve it mathematically, because grid vertex positioning is predictable. But I'm not a fan of solving a specific case because the way the question is phrased, future folk looking for a problem will probably look for a solution involving arbitrary geometry. – Markus von Broady Nov 26 '22 at 14:33
  • @MarkusvonBroady OK, then the misunderstanding was definitely mine alone ;-) Anyway, I currently don't have a very good idea how this task could be solved (procedurally & performantly). – quellenform Nov 26 '22 at 14:48

0 Answers0