Closest Vector how can i script this in grasshopper itself?

Hi All,

pufferfish closest vector is too good

out of curiosity am trying to rebuild the script in grasshopper itself (with out using plugin)

how can i make make this happen (with out using phyton and c#)

cheers
rajeev

Just use the standard closest point component - it gives you exactly the same thing.
(and if you only want to compare by angle, unitize the vectors first)

3 Likes

thanks @DanielPiker
it gave me a start up i made some thing
is there any better ways of doing it
closest vector.gh (14.4 KB)

1 Like

It doesn’t need to be so complicated. This is all you need!
image

5 Likes

This works because if a component requires a point input and you give it a vector, Grasshopper automatically converts that vector into a point with the same coordinates. If these points are close, the vectors are close. If you unitize the vectors then the ones that are close in angle are also close in space.

3 Likes

As a curiosity, many other graphic engines do not distinguish between point and vector. Both are an object with numerical coordinates, you can interpret these coordinates as the position in a space or as the direction that goes from the origin of space to that position. These are equivalent and many of their operations make sense in both interpretations.

2 Likes

@DanielPiker
oh my god !! that was so simple !!
thank u so much

2 Likes

It’s bothersome to have to cast directly from points to vectors when scripting.

FWIW in that component I just iterate over

https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Vector3d_VectorAngle.htm

And pick the smallest angle and keep track of indices. Simple but fun, I’m pretty sure it was my first c# component :smiley: was a good small example of index tracking.

As you see Grasshopper has some nifty conversion tricks, although not so obvious.

1 Like