Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Distance from point to set

  • To: mathgroup at smc.vnet.net
  • Subject: [mg55411] Re: Distance from point to set
  • From: Piotr Kowalski <pkowalsk at ibspan.waw.pl>
  • Date: Tue, 22 Mar 2005 03:51:01 -0500 (EST)
  • References: <d1eblq$ek7$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hello,

Thank you for all your replies.
Here is the summary of different solutions obtained:

----
Jens-Peer Kuska, kuska at informatik.uni-leipzig.de
distanceToSet[pnt_, pset_] := Min[Sqrt[#.#] &[# - pnt] & /@ pset]
----
Bob Hanlon, hanlonr at cox.net
dist1[pt_, ptList_] := Module[{d},
       Sqrt[(d=#-pt).d]&/@ptList];
and in version 5
dist2[pt_, ptList_, p_:2] := Norm[pt-#,p]&/@ptList;
----
Peter Pein, petsie at arcor.de
In[2]:= (* definition of the distance *)
   d[el_, set_, p_:Infinity] := Min[(Norm[el - #1, p] & ) /@ set]
----
David Park, djmp at earthlink.net
distance[set_][point_] :=
   Min[(Sqrt[Plus @@ ((point - #1)2)] & ) /@ set]
----
Andrzej Kozlowski, akoz at mimuw.edu.pl
If you have Mathematica 5 or above you can use simply:
dist[p_, l_, n_:2] := Min[Norm[#, n] & /@ Transpose[Transpose[l] - p]]
----
Steve Luttrell, steve_usenet at _removemefirst_luttrell.org.uk
Here is how you would define a function to do this for a Euclidean 
distance measure:
d[x_,A_]:=Min[Map[#.#&[x-#]&,A]];

More generally you could pass a 3rd argument to this function to
specify a function for measuring distance:
d[x_,A_,norm_]:=Min[Map[norm[x,#]&,A]];
----

I have learned here (among others) about nice new function Norm[var,p]
for Mathematica 5.x but unfortunately, I have only access to
Mathematica 4.1 at present.

The solutions presented above are for the discrete set A, containing
finite number of points (list of points in Mathematica).

And what in the case, when  the set A is described by some
linear inequalities (giving for example convex cone)
or nonlinear inequalities and not finite number of points ?
I've got information by private e-mail about NMinimize function
(in Mathematica 5.x) or package MathOptimizer for Mathematica 3.x,4.x,5.x.
Are there any other approaches to such problem in Mathematica?

Thank you in advance,
Piotr Kowalski






> Hello,
> 
> I would like to compute distance d(x,A) from a point 'x' to a set 'A',
> (all in R^n, where n=2 or n=3) that is:
> 
>    d(x,A) = min ||x - a|| (forall a in A)
>    where: n=2 or n=3,
>           x is point in R^n, A is subset of R^n
>           ||  || is norm (euclidean, max, etc).
> 
> Can I find Mathematica function or package for such problem ?
> 
> Thank you in advance,
> P. Kowalski
> 


  • Prev by Date: Re: Restriction on the domain of Plot3D
  • Next by Date: Re: TrigExpand - Odd behavior
  • Previous by thread: Re: Distance from point to set
  • Next by thread: Problem with singularities in Plot3D