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

1 次查看(过去 30 天)
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.

更多回答(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