For example on an object like a banana, a snake or a C shaped object.
Is there a way to find the 2 "endpoints" or the 2 vertices that are furthest apart using geometry nodes?
For example on an object like a banana, a snake or a C shaped object.
Is there a way to find the 2 "endpoints" or the 2 vertices that are furthest apart using geometry nodes?
This is the most efficient way I could find: rather than measuring distances between each pair of points, I'm making a copy (copying has to be done in order to iterate on every possible pair - and a repeat zone is in general much slower than the old ways) and moving chosen point to the origin. Now the distance to this point is just the length of the position vector:
As Don Hatch notices in a comment, the "Delete Geometry" node is not required (and removing it speeds up the setup). You would want this node if the criterion for picking a point wasn't being furthest, but something that could cause a point to evaluate itself (its copy) as a winner. In such case you would keep this node. For example if "Index of Nearest" node didn't exist or if you wanted to find the nearest unconnected point (in this case you would need to blur the selection with 1 iteration to also delete immediately connected points).
You can use this group like so:
Robin Betts' convex hull optimization:
Here are a couple of variations on Markus von Broady's solution. They both are still based on Markus's "quadratic geometry explosion" method (that is, explicitly constructing in memory the entire Minkowski sum of the point set A with -A), so if you try to use them on inputs a lot larger than Suzanne, you will have a bad time :-/
My first thought on looking at Markus's solution was that the method of finding the index at which a maximum occurs looks a bit shocking-- surely there's a more direct way to implement "index of max"?
But it seems that "Attribute Statistic (Max)" really doesn't provide a convenient way to get the index at which the max occurred. I tried searching all over for geom accumulation nodes that do return an index, that we might be able to leverage for this. The only things I found were "Index of Nearest" (which I couldn't figure out how to use at all) and "Sample Nearest". "Sample Nearest" can do almost what we want-- it can tell us the index of the point nearest the origin. But we want the point farthest from the origin instead. To do that, we can just use the "inverses" of the points (i.e. each point divided by its distance-from-origin squared), and ask which one of those is nearest the origin.
So, in this variation, I do the following:
Use an "Inverse of Position" node group, followed by "Sample Nearest", to get the index of the point farthest from the origin in the Minkowski sum object.
Also, instead of capturing the original indices on the two factor geometries and threading those through the product, I recover them from the index-into-the-big-object using math-- simply div and mod the big index by the original number of points.
Here's the "Inverse of Position" node, expanded:
I thought this was all clever and neat, but unfortunately it seems to be 7.5 times as slow as Markus's original solution :-(
(That's according to the Timings annotations in the geom node graph editor, on Suzanne with "Subdivision Surface" modifier, which increases number of vertices from 507 to 2012... and without taking convex hull.)
Abandoning the too-slow "Inverse of Position" -> "Sample Nearest" strategy, I tried to at least salvage the recover-the-two-indices-using-math part (which seems like a simplification, and I was hoping maybe a performance improvement too). So that means going back to the original shockingly-clunky-but-reasonably-fast method of finding the index at which a maximum occurs. I encapsulated this into an "Index of Max" node group, so at least it looks tidy from the outside.
And here's the "Index of Max" node, expanded: 
This variation seems to be the same speed as Markus's original solution (with the "Delete Geometry" node muted). So there was no measurable performance gain here after all-- the main thing of value here, perhaps, is just the reusable "Index of Max" node.