I was trying to recreate the closest Point component in c#.
It works for 1 Point as Attractor. How do I need to change for appying more than one?
Or is should it be done with a PointCloud? In this case, how do I get the distances? when the PointCloud is returning just the index of the closest point?
To find the (distance to the) closest point in a collection of points, you’d have to do something like this:
double minDistance = double.MaxValue;
for (int i = 0; i < points.Count; i++)
// you could also use a foreach loop if you don't care about indices)
double localDistance = locus.DistanceTo(points[i]);
minDistance = Math.Min(minDistance, localDistance);
However in RhinoCommon this functionality is readily available from the Point3dList class as ClosestIndex, ClosestIndexInList and ClosestPointInList. The latter two methods are static, meaning you can use them on other collections, such as List<Point3d>, Point3d, ImmutableArray<Point3d>, etc.
Best to stay away from PointClouds in Grasshopper.
With one point as attractor I was able to reproduce, but I have no idea how it works with more than one.
I thought it was maybe a averaging of the points, but I couldnt find it out,
Maybe you could give me a hint. Would be really apreciated.
Still the same code. It doesn’t matter how many points you’re measuring the distance to. You just have to iterate over all your points in the population, which is what you’re doing with the Closest Point component too. As you’ll see, the P input is of type ITEM and the C input (your attractors) are of type LIST.
Surely you’re not comparing the same numbers here? Inside the script you’re running the logic on the lists if points. Outside the script you’re taking only the results of the iterations into account. Those are wholly different number sets.