How to know A, B, C, D four positions in a rectangle generated by impoly?

조회 수: 2 (최근 30일)
Meshooo
Meshooo 2016년 3월 11일
편집: Meshooo 2016년 3월 18일
Dear all,
If I have the four coordinate corner positions of a rectangle shape. The positions of A, B, C, D are like the image I show here. So A is the closest point to (0,0) and B is to the right from A and and so on.
Any suggestion will be appreciated.
Meshoo

채택된 답변

Guillaume
Guillaume 2016년 3월 11일
I doubt you want A to be point closest to (0,0), e.g, in the case [1, 100; 2, 0; 1, 200; 2, 200] the closest point to 0 is [2, 0] but I assume you still want A to be [1, 100].
I assume your quadrilateral is convex (otherwise you can make three different simple quadrilaterals with the four points) and you're trying to find the order of the vertices so that they form a simple quadrilateral
You can find the order of the vertices from convhull:
Array_1 = [84 113;76 237;108 235;106 115];
order = convhull(Array_1);
assert(numel(order) == 5, 'Points do not form a convex quadrilateral');
orderedpoints = Array_1(order(1:4), :)
orderedpoints will be ordered in counter-clockwise direction, so if you plot them they will always form a simple quadrilateral.
plot(Array_1(order, 1), Array_1(order, 2)); %guaranteed to plot a simple quadrilateral
I'm not sure how to work out which of the points is A, but once you've worked it out, you can simply rearrange the points with circshift. E.g if you decide that point 2 in the reordered array is A, then
ptAidx = 2;
ACDB = circshift(orderedpoints, 1-ptAidx, 1) %guaranted to be ordered as A, C, D, B
Finding the top left corner is actually a difficult problem that is also ambiguous in some cases, so possibly just identifying which order of points form a simple quadrilateral is enough for you.
  댓글 수: 2
Meshooo
Meshooo 2016년 3월 12일
Ok thank you very much. Will try that shortly.
Meshooo
Meshooo 2016년 3월 15일
편집: Meshooo 2016년 3월 15일
Oh! I just noticed that it will fail if the quadrilateral is square.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by