Skip to main content

regions - Find nearest distance of an interior point from perimeter


By definition, the interior point is a point inside an arbitrary region like this:


enter image description here


In picture above, $y$ is an interior point of region. My question is how to find the distance of an interior point from it's boundary?


I have this Idea: By using the polygons, we can approximate the perimeter of region by a n-gon (n is large enough). Then by saving the coordinates of perimeter in two vectors, say $x$ and $y$, and use Nearest command we can find nearest point of perimeter from interior point ($y$).


I created data matrices (find from here) in MATLAB and import to Mathematica.



imp = Import["PI.mat", "LabeledData"];
X = "KP" /. imp;
Y = "KI" /. imp;

But I can't know how to use Nearest command when we have large vectors like X and Y :


Nearest[{Flatten@X, Flatten@Y}, {3, 1.5}]

An error appears, because Flatten@X, Flatten@Y and {3, 1.5} are not the same length.



Answer



Assuming I interpreted your data correctly...



imp = Import["C:\\Users\\Rasher\\Downloads\\" <> "PI.mat", "LabeledData"];

(* get data into flat lists *)
X = "KP" /. imp // Flatten;
Y = "KI" /. imp // Flatten;

(* turn into X,Y point-sets *)
pts = Transpose[{X, Y}];

(* Find some point to boundary of poly *)

Nearest[pts, {3, 1.5}]

(* {{2.67062, 2.7767}} *)

Comments