Re: Distance from point to set
- To: mathgroup at smc.vnet.net
- Subject: [mg55324] Re: [mg55273] Distance from point to set
- From: "David Park" <djmp at earthlink.net>
- Date: Sat, 19 Mar 2005 04:45:32 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Piotr, pointset = Table[{Random[Real, {-1, 1}], Random[Real, {-1, 1}]}, {15}] {{0.5305433510989825, -0.9835285661296697}, {0.5149981888311421, 0.07030452237485907}, {-0.5548609965862412, -0.6706534564593198}, {0.4558425442584053, -0.12739148149428103}, {-0.9655103281065733, -0.05179566007389713}, {0.4904660178309532, 0.8356363263603159}, {0.16628343930149758, -0.042530943920831454}, {0.3659938304114865, 0.8630592267325137}, {0.5645610817860498, 0.628260167352799}, {0.8354119739988664, 0.47802415636698714}, {0.3895290445491575, -0.6189409509144874}, {0.6809555054832066, -0.4166538650333329}, {0.858985693450175, -0.6354123847848178}, {-0.8340426833479355, 0.513041612591808}, {0.41384669003641616, -0.9647589283254978}} distance[set_][point_] := Min[(Sqrt[Plus @@ ((point - #1)^2)] & ) /@ set] distance[pointset][{2, 2}] 1.90642 For a 3D case... pointset3d = Table[{Random[Real, {-1, 1}], Random[Real, {-1, 1}], Random[Real, {-1, 1}]}, {5}] {{-0.3514875029445578, -0.4986924916835682, -0.981757049847647}, {0.46371338462627243, 0.25898345250628485, -0.8797515407690808}, {-0.6627125553308537, -0.11963275034039467, 0.3999977590561097}, {0.7556608440157371, -0.8286698719829182, 0.3673256370677973}, {0.9861510690196937, 0.7204197723412349, 0.46121535562342286}} distance[pointset3d][{2, 2, 1}] 1.71916 David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Piotr Kowalski [mailto:pkowalsk at ibspan.waw.pl] To: mathgroup at smc.vnet.net 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