[Date Index]
[Thread Index]
[Author Index]
Re: Distance from point to set
*To*: mathgroup at smc.vnet.net
*Subject*: [mg55329] Re: [mg55273] Distance from point to set
*From*: Andrzej Kozlowski <akoz at mimuw.edu.pl>
*Date*: Sat, 19 Mar 2005 04:45:50 -0500 (EST)
*References*: <200503181033.FAA14616@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
On 18 Mar 2005, at 11:33, Piotr Kowalski wrote:
> 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
>
If you have Mathematica 5 or above you can use simply:
dist[p_, l_, n_:2] := Min[Norm[#, n] & /@ Transpose[Transpose[l] - p]]
For example, let
In[2]:=
p = {x, y}; l = {{a, b}, {c, d}};
then
In[3]:=
dist[p, l]
Out[3]=
Min[Sqrt[Abs[a - x]^2 + Abs[b - y]^2],
Sqrt[Abs[c - x]^2 + Abs[d - y]^2]]
In[4]:=
dist[p, l, 4]
Out[4]=
Min[(Abs[a - x]^4 + Abs[b - y]^4)^(1/4),
(Abs[c - x]^4 + Abs[d - y]^4)^(1/4)]
In[5]:=
dist[p, l, Infinity]
Out[5]=
Min[Max[Abs[a - x], Abs[b - y]], Max[Abs[c - x],
Abs[d - y]]]
Andrzej Kozlowski
Chiba, Japan
http://www.akikoz.net/andrzej/index.html
http://www.mimuw.edu.pl/~akoz/
Prev by Date:
**Re: Wolfram plugin for Google Desktop Search**
Next by Date:
**Re: plotting weighted graphs**
Previous by thread:
** Distance from point to set**
Next by thread:
**Import Problem**
| |