Re: Interpoint distances
- To: mathgroup at smc.vnet.net
- Subject: [mg41353] Re: [mg41327] Interpoint distances
- From: jmt <jmt at dxdydz.net>
- Date: Thu, 15 May 2003 04:09:03 -0400 (EDT)
- References: <200305141220.IAA07863@smc.vnet.net>
- Reply-to: jmt at dxdydz.net
- Sender: owner-wri-mathgroup at wolfram.com
One remark first : in many applications, the euclidian distance needs not to be computed since most of the time the square of the euclidian distance will suffice. Computing a square root when not necessary will burden your algorithm. Second remark : your example suggests that you want to compute the interpoint distance of a set of points. Depending on the size of this set, Mathematica will or will not use PackedArray. It is then difficult to give a universal answer. On Wednesday 14 May 2003 14:20, DIAMOND Mark R. wrote: > I am trying to find an efficient method of calculating all the > pairwise (Euclidean) interpoint distances in a given list of points > in R^2. I am sure that if my matrix algebra were any good, this would > be solvable in a better manner than I have done it. Ideally, I would > like to count each pair of points only once, and not count points > paired with themselves.I've searched the archive, and tried the > obvious combinations of words on Google, but no luck. > > My slow method (but the fastest of those I've tried) is > > (* Define a distance function for a pair of points *) > distance[{{x0_, y0_}, {x1_, y1_}}] := Module[ > { > xd = x0 - x1, > yd = y0 - y1 > }, > Sqrt[xd^2 + yd^2] > ] > > (* Create a list of random points with which to experiment *) > t=Table[{Random[], Random[]}, {1024}] > > (* Union in the next line is just used to get rid of all the > duplicates, and to dump all but one of the 0 interpoint distances > between a point and itself *) > interpointDistances = Union[Map[distance, Flatten[Outer[List, t, t, > 1], 1]]]; > > I would be very grateful for any suggestions for improvement. > > Cheers, > > Mark > -- > Mark R. Diamond
- References:
- Interpoint distances
- From: "DIAMOND Mark R." <dot@dot.dot>
- Interpoint distances