Skip to main content

vJSONSortByDistance

Reorders points into a nearest-neighbor chain that starts at the first point.

BeginnerMograph / JSONJSONArrayScriptVal
vJSONSortByDistance node

vJSONSortByDistance takes an array of XYZ points and outputs them in a new order: the first point, then the closest unused point to it, and so on. Distance Mode decides what happens when the closest point is farther than Smallest Distance.

Parameters​

ParameterTypeDefaultDescription
Smallest DistanceFloat1.0Largest step allowed in Strict mode. Not used in Preferred mode. Minimum 0, slider 0 to 10, default 1.
Distance ModeDropdownPreferredPreferred (default) always steps to the closest unused point. Strict stops the chain when that point is not closer than Smallest Distance.
InputDATATYPE—Points to sort.
Read the full description

The first input point stays first. Each next point is the unused point that is closest to the one before, which avoids long jumps when points are drawn in order. Points that are not lists of at least 3 values are dropped, and each output point has 3 values.

In Preferred mode (default) the chain always continues with the closest unused point, whatever its distance. In Strict mode the chain stops at the first step where no unused point is closer than Smallest Distance (default 1) to the last point. The points not reached are then added after the chain in their input order. The search compares every unused point at every step, so it slows down with the square of the point count.

Example Connections​

vJSONRandom.Output -> vJSONSortByDistance.Array
vJSONSortByDistance.Output -> vJSONCameraProjection.ArrayA
vJSONCameraProjection.Output -> vJSONShapeRender.ArrayPoint
Background.Output -> vJSONShapeRender.Input