# 3.9.2: Closest Points

Assume you have two sets of points: say **“P”** and **“C”**. Further imagine you want to have a network that connects each point of the first set with a predefined number of its nearest neighbors in the second set (input **“N”**) or to points in set two that lie within a given distance **“LDist”**. In that case the “Nearest Neighbor”-component will be the right choice (see fig. 3.9.2.1). It outputs at **“P”** a data tree with branches containing the points of set **“C”** which are closest to the **“P”**-points. The order of branches corresponds to the points in **“P”**. The output **“i”** returns the indexes of the nodes in **“C”**, and **“D”** the distances.

![Fig. 3.9.2.1: A grid of points where each point connects to one or two of its nearest neighbors](https://2671626451-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCkDlhlZpqUmakSqOrp%2Fsync%2Fdf7897ed89bef137f554db5878c5776de7c47306.PNG?generation=1595316050770210\&alt=media)

{% file src="<https://2671626451-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6rkhS8IteqWJRfUuJlL5%2Fuploads%2FZOgZSZfshwy4Tuj11W3T%2FNearest_Neighbors_I.gh?alt=media&token=248cc8d9-7e10-4bf4-9ba8-6172746390ee>" %}

{% file src="<https://2671626451-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6rkhS8IteqWJRfUuJlL5%2Fuploads%2FDsNBJDXBp0z8An3MPFMd%2FNearest_Neighbors_II.gh?alt=media&token=158819d4-b777-48b1-8fd9-30e455a23a83>" %}
