Pick nearest?

Hello vvvvolks!

Once again I need your help! I need to get the slice(index) of a spread defined by the smallest distance to another element. In other words: the index of the element of a spread which is closest to certain (fluctuating) coordinates.

cheers!

Pez

check the “Former Index” output of the Sort node and take the last (or first) slice of it.

Points2Vector will give you the distance between two 2d points. when using spreads you can e.g. calculate the distance from any point to a given point.

see the patches below.
for 1d and 3d.
michel.

minimal_distance.rar (3.6 kB)

michels 3d patch is rigth, but can be optimized by using the Polar (3d) node, which calculates the lenght of the difference vectors …

min_disances_3dOptimized.v4p (15.5 kB)

thanks alot for your tip with polar (3d), tonfilm.
until now i did the length calculation with expr.
your method is much faster (factor 30!!!)

is expr lame, should it be avoided with larger spreadcounds or am i doing something wrong?

see attached patches…

cheers ele

ComparePerformance.rar (2.5 kB)

is expr lame, should it be avoided with larger spreadcounds or am i
doing something wrong?

in theory expr should compile the math expression to some internal stucture once and just run through that for each slice. this should be quite fast, but is necessarily slower than the polar node, which is purely writen in delphi.

factor 30 seems to be a lot though…