MATLAB Answers


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

Meshooo 님이 질문을 제출함. 11 Mar 2016
최근 활동 Meshooo 님이 편집함. 18 Mar 2016
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.

  댓글 수: 0

로그인 to comment.

답변 수: 1

Guillaume 님의 답변 11 Mar 2016
 채택된 답변

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

Ok thank you very much. Will try that shortly.
Oh! I just noticed that it will fail if the quadrilateral is square.

로그인 to comment.

Translated by