Optimize ClosestPoint

Hi, I brought a problem…

I have tons of points, and need to get (u,v)s of a surface from the points.
There are tons of points and currently ClosestPoint is making a big bottleneck.
Is there any way to substantially speed up ClosestPoint?
I think there is no magic, but maybe some geniuses in this forum know a magic.

Flipping the way is not an option. There are actually two surfaces. Even if the points are generated from a uv grid on one surface, a bunch of ClosestPoint needs to be called on the second surface.

You would have to provide a picture or a file for anyone to see it the approach to your problem can be optimized.

// Rolf

Hi sorry for the insufficient input.
Please see the attached image.
There is a point. I need its (u,v) coordinates on two surfaces. You can assume the point is originally generated from a u-v coordinates on one surface. But anyway there is the second surface.
Thanks!

By file, it means your actual Grasshopper definition (or the part you need to optimize on), rather than a conceptual diagram.

He said picture OR file, but okaaay, here you go…closestpoint.gh (33.2 KB)

The surface in the GH definition is a circle, but it is only for simplicity. The shape may be more arbitrary. So the algorithm cannot assume it’s a circle.

On average and for ~2K random test points this takes 30 to 70 ms (i9 10xxxK VS some pathetic i5). If you have way bigger collections and you are after “real-time” (kinda) results you’ll need some thread safe // solution (provided that there’s some cores available).

Hi, thanks for the reply.
There are (36-4)(36-4)4x4x4x4=262144 points currently and it is likely ‘36’ needs to go high up to 200.
I really thought there is no solution as it is just an inverse of (u,v)->(x,y).
But now I see the GH def I posted by myself, and came up an idea.
The points are very dense, and most likely ordered. So maybe a new ClosestPoint() that takes an initial guess of u,v would be a great help. Please somebody write a code :pray: :pray: :pray:

Nothing is free in this world: any “guess” requires also time.

BTW: For 1M points indeed you’ll need a proper i9 (6++ cores) and a // solution . But right now I’m in the middle of nowhere doing some loops (windsurf stuff … not C#). Since there’s no plans to return in action soon … you need some other good Samaritan.

No, no, what I meant was the uv of the previous point can be re-used as the initial guess of the next point.

Hard to see the benefit I confess.

BTW: Using a laptop (pathetic i5) full with sand for 30K rnd test points you need around 2000 ms. (maybe 1000 in an i9 K - hope dies last), So for 1.2 M pts and 32 cores … blah, blah.

1 Like