Skip to content

Latest commit

 

History

History
75 lines (54 loc) · 1.37 KB

neighborsearch.md

File metadata and controls

75 lines (54 loc) · 1.37 KB

Neighbor search

using Meshes # hide
import CairoMakie as Mke # hide

It is often useful to search neighbor elements in a domain given a point of reference. This can be performed with search methods:

NeighborSearchMethod
search
search!
searchdists
searchdists!

Search methods are constructed with various types of parameters. One may be interested in k-nearest neighbors, or interested in neighbors within a certain Neighborhood:

Neighborhood
MetricBall

The following example demonstrates neighbor search with the KNearestSearch method:

grid = CartesianGrid(10, 10)

# 4-nearest neighbors
searcher = KNearestSearch(grid, 4)

inds = search(Point(5.0, 5.0), searcher)

The function search returns the indices of the elements in the domain that are neighbors of the point. The elements are:

grid[inds]

Alternatively, the function searchdists also returns the distances to the (centroids) of the elements:

inds, dists = searchdists(Point(5.0, 5.0), searcher)

dists

Finally, the functions search! and searchdists! can be used in hot loops to avoid unnecessary memory allocations.

BallSearch

BallSearch

KNearestSearch

KNearestSearch

KBallSearch

KBallSearch