Find inner points among a set of points on a regular grid

조회 수: 9 (최근 30일)
Kai
Kai 2018년 9월 6일
편집: Matt J 2018년 9월 6일
I am dealing with the following problem:
Given a two-dimensional regular grid G = [a*h:h:b*h]x[c*h:h:d*h] and a subset S of G (i.e. a collection of knots on G), find the elements of S which lie on the inner of a 4x4 region of points of S.
In my situation, S usually looks like an "island" of points, and I am trying to select the points which do not lie on the coast, so to say. You could also think of a chess board with many kings placed and you want to find those kings which are unable to move (I know, "many kings" is a little imaginary). A 3x3 region as a selection criterion would be right for this situation actually, but it could lead to "one-dimensional lines" of inner points, which is not what I want (since I am actually interested in the regions between four inner points).
I made some straightforward implementation: When considering a point P, I run four loops which check whether P is the (2,2), (2,3), (3,2) or (3,3) position of such a 4x4 region respectively. Inside such a loop, for all other 15 positions of the 4x4 regions I check if S contains a point at this position. If there exist points at all 15 positions, the point P is marked as an inner point and I end the loops using the break command.
The implementation works, however it is quite costly. In my overall program, I have several such subsets S, and I would like to work with grids as fine as possible (resulting in large sets S). Checking 15 positions as above means running the isempty command 15 times, and the input for this command consists of four inequations each time (checking both coordinates seperately and using some eps tolerance bound, since sometimes there are rounding issues), each inequation being checked for every element of S.
I am wondering if there is some more elegant and quicker way to solve the problem, without spending weeks of defining some efficient searching algorithm or so. Perhaps there is even some Matlab function which I can use but haven't thought of (I searched using some keywords, but did not find anything useful).

답변 (2개)

KSSV
KSSV 2018년 9월 6일
Read about inpolygon.
  댓글 수: 4
KSSV
KSSV 2018년 9월 6일
Try knnsearch or rangesearch
Kai
Kai 2018년 9월 6일
Hmm, rangesearch could be an idea. I will try that, thank you!

댓글을 달려면 로그인하십시오.


Matt J
Matt J 2018년 9월 6일
편집: Matt J 2018년 9월 6일
Make a binary map BW of S and use imerode,
[I,J]=find( imerode(BW,ones(4));

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by