Curve Closest Point Problem

I am having trouble with closest point command. It doesn’t seem to find the closest point.

Mesh and alignment - VAL - R1 - (12.8 MB)

You need to graft the points and flatten the curves.

Mesh and alignment - VAL - R1 - (12.8 MB)

I am not hundred percent sure what’s happened here, but I can see it works. So, you get the closest points and sort them per distance? And then grafted - which doesn’t do anything without the sorting. I am missing the reasoning behind sorting.
Because. I imagined that the closest points to my populations are automatically calculated by the Grasshopper, and they are in the order of my population, so I can just draw the line. But appearently, I am wrong.

As you can see below, the distances are listed by curve order, three distances per point, so you have to sort by distance to get the shortest one. Each populated point needs to be treated individually which is why you graft.

Hi Ethan,
This approach didn’t work in simpler version here. Please see the attachment. I noted the working approach and not-working approach with scribble in the code.
(I am trying to create a code that will work on all situations, of course)
(Thanks a lot for the help and sorry for multiple questions.)
HeatMapStudy-R1-PopulateEdit.3dm (32.8 KB) (8.4 KB)

It’s not working here because you are sorting among all the 42 points in one branch, not among the three points in each branch in the first example. You’re dealing with three curves on top and one curve here. Different data structures. Try adding a second curve to this example and see what happens…

Got you. Instead of grafting, can we find a solution to connect the curves in the first example so it works in all of them?

I don’t get it, it works if you graft your Points in the second example (or at least I think it does, you want to connect each point to the nearest curve, right ?). Or course sorting projections is then useless because there is a single element to sort, but this will cover the general case.

Grafting/Flattening is not that impossible to understand, you just need to rephrase what you want to do in simple terms that include “each” and “all”.

Here, you want to project each point to all the curves, and select the nearest one.
“each” means you need a tree structure with a single element in each branch, so you Graft.
“all” means you need a list structure containing all the “target” elements, so you Flatten.

Hi, you are 100% right, there was unclear parts in my questions. I have curve and surface which has points on it (population). I want to find the closest points of curves to the points on the surface.
Can there be an easier option by combining the three curves in the first example?
I just noticed second example doesn’t work, I will update it.
In the example you made, you can see the first three points “supposed-to-be” location:

This is not a problem of tree structure, but a geometry problem. Your input curve is too short !
You can use Extend Curve to extend it so the projections work as you wish.

Yes, I noticed that. I will post again.