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

1 visualización (últimos 30 días)
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

Respuesta aceptada

Guillaume
Guillaume el 11 de Mzo. de 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 comentarios
Meshooo
Meshooo el 12 de Mzo. de 2016
Ok thank you very much. Will try that shortly.
Meshooo
Meshooo el 15 de Mzo. de 2016
Editada: Meshooo el 15 de Mzo. de 2016
Oh! I just noticed that it will fail if the quadrilateral is square.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by