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

2 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Guillaume
Guillaume am 11 Mär. 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 Kommentare
Meshooo
Meshooo am 12 Mär. 2016
Ok thank you very much. Will try that shortly.
Meshooo
Meshooo am 15 Mär. 2016
Bearbeitet: Meshooo am 15 Mär. 2016
Oh! I just noticed that it will fail if the quadrilateral is square.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by