Documentation for jbiu/

Generated by IDLdoc

single page | use frames     summary     class     fields     routine details     file attributes

astro/

match_nd.pro


top source match_nd

Astro

result = match_nd(p1, p2, maxdistance, mindist=mindist, one_to_one=one_to_one)

For each arbitrarily-dimensioned point in one vector, determines the closest point in a second vector. Method is to take the list returned by MATCHALL_ND and narrow it down to the closest match.

Return value

The function returns an array with one entry for each P1 element containing the index in P2 that is closest, or -1 if there are none within MaxDistance.

Parameters

p1 in

N1 x D array of D-dimensional coordinates.

p2 in

N2 x D array of D-dimensional coordinates.

maxdistance in

Maximum D-dimensional distance.

Keywords

mindist in

Optional output containing an array of the actual distance to the closest match for each element of P1.

one_to_one in

Enforces one-to-one matching. By default, matching can be many-to-one, i.e. one entry in P2 can be the closest match to several entries in P1. If /ONE_TO_ONE is given, then each multiple entry in P2 is first assigned to its closest point in P1. Then any entries in P1 that have lost their match are assigned the next closest point within MaxDistance. This process is iterated until all points in P1 are matched to a unique point in P2 or there are no more points within MaxDistance.

Examples

na = 10 nb = 1000 a = randomn(seed, na, 3) b = 2. * randomu(seed, nb, 3) - 1 matches = match_nd(a, b, 0.3) iplot, /scatter, /iso, b[*,0], b[*,1], b[*,2] iplot, /overplot, /scatter, a[*,0], a[*,1], a[*,2], sym_index=6, $ sym_color=[255,0,0] for i=0L, na-1 do if matches[i] ne -1 then $ iplot, /overplot, [a[i,0], b[matches[i],0]], [a[i,1], b[matches[i],1]], $ [a[i,2], b[matches[i],2]], sym_index=0, color=[255,0,0]

Author information

History:

Written by: Jeremy Bailin 10 June 2008 Public release in JBIU as WITHINSPHRAD 24 April 2009 Vectorized as WITHINSPHRAD_VEC 25 April 2009 Polished to improve memory use 9 May 2009 Radical efficiency re-write as WITHINSPHRAD_VEC3D borrowing heavily from JD Smith's MATCH_2D 13 May 2009 Removed * from LHS index in final remapping for speed 23 August 2010 Modified to only return closest match as WITHINSPHRAD_CLOSEST (importing some stuff back from MATCH_2D) 8 Sept 2010 Renamed MATCH_SPH. Added /ONE_TO_ONE option, and modified to explicitly call MATCHALL_SPH and then cull. 9 Feb 2011 Forked as MATCH_ND to handle Euclidean case of arbitrary dimension. 13 April 2011 Fixed to work around cumulative total 1-element array bug.

File attributes

Modification date: Wed Apr 13 17:00:28 2011
Lines: 164