MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Interpoint distances

  • To: mathgroup at smc.vnet.net
  • Subject: [mg41327] Interpoint distances
  • From: "DIAMOND Mark R." <dot at dot.dot>
  • Date: Wed, 14 May 2003 08:20:03 -0400 (EDT)
  • Organization: The University of Western Australia
  • Sender: owner-wri-mathgroup at wolfram.com

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







  • Prev by Date: Re: Apart, Factor on different operations
  • Next by Date: Re: which one is greater than or equal?
  • Previous by thread: Re: Re: Euler's Gamma and Beta Functions
  • Next by thread: Re: Interpoint distances