       Re: Distance from point to set

• To: mathgroup at smc.vnet.net
• Subject: [mg55313] Re: [mg55273] Distance from point to set
• From: Bob Hanlon <hanlonr at cox.net>
• Date: Sat, 19 Mar 2005 04:45:14 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```dist1[pt_, ptList_] := Module[{d},
Sqrt[(d=#-pt).d]&/@ptList];

pts2 = {{x1,y1},{x2,y2},{x3,y3}};

pts3 = {{x1,y1,z1},{x2,y2,z2},{x3,y3,z3}};

d12=dist1[{x,y},pts2]

{Sqrt[(x1 - x)^2 + (y1 - y)^2],
Sqrt[(x2 - x)^2 + (y2 - y)^2],
Sqrt[(x3 - x)^2 + (y3 - y)^2]}

d13=dist1[{x,y,z},pts3]

{Sqrt[(x1 - x)^2 + (y1 - y)^2 + (z1 - z)^2],
Sqrt[(x2 - x)^2 + (y2 - y)^2 + (z2 - z)^2],
Sqrt[(x3 - x)^2 + (y3 - y)^2 + (z3 - z)^2]}

In version 5

dist2[pt_, ptList_, p_:2] := Norm[pt-#,p]&/@ptList;

d22=dist2[{x,y},pts2]

{Sqrt[Abs[x - x1]^2 + Abs[y - y1]^2],
Sqrt[Abs[x - x2]^2 + Abs[y - y2]^2],
Sqrt[Abs[x - x3]^2 + Abs[y - y3]^2]}

Reduce[d22==d12,Reals]

True

pts = {{x1,y1,z1},{x2,y2,z2},{x3,y3,z3}};

d23=dist2[{x,y,z},pts3]

{Sqrt[Abs[x - x1]^2 + Abs[y - y1]^2 + Abs[z - z1]^2],
Sqrt[Abs[x - x2]^2 + Abs[y - y2]^2 + Abs[z - z2]^2],
Sqrt[Abs[x - x3]^2 + Abs[y - y3]^2 + Abs[z - z3]^2]}

Reduce[d23==d13,Reals]

True

dist2[{x,y},pts2,1]

{Abs[x - x1] + Abs[y - y1], Abs[x - x2] + Abs[y - y2],
Abs[x - x3] + Abs[y - y3]}

dist2[{x,y},pts2,Infinity]

{Max[Abs[x - x1], Abs[y - y1]], Max[Abs[x - x2],
Abs[y - y2]], Max[Abs[x - x3], Abs[y - y3]]}

Bob Hanlon

>
> From: Piotr Kowalski <pkowalsk at ibspan.waw.pl>
To: mathgroup at smc.vnet.net
> Date: 2005/03/18 Fri AM 05:33:49 EST
> To: mathgroup at smc.vnet.net
> Subject: [mg55313] [mg55273]  Distance from point to set
>
> 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 ?
>