How to identify the relative location of points on a rectangle (or general polygon)?

4 visualizzazioni (ultimi 30 giorni)
This is more of a mental challenge that a programming one, but I have drawn a polygon with insertShape and I want to be able to identify the top left, top right, bottom left and bottom right points (TL TR BL BR) for any 4 points of a rectangle. For instance, the points
[1 3; 2 5; 4 6; 3 4]
has TL, TR, BR, BL in that order, given that we read the full image size with 1 1 as top left and 6,6 as bottom right.
Example 2:
[2 2; 4 3; 5 2; 4 3; 3 1]
has TR BR BL TL
The order of the points between the brackets can begin with any point and end with any point, so the answer above should give the same corespondance between points and positions if the order of the points was differently arranged. In other words,
[4 3; 5 2; 4 3; 3 1; 2 2]
has BR BL TL TR, same as above.
If I could generalize this to the points of any size polygon that would be great, but I'm mainly after a solution for a rectangle.
Thanks!

Risposte (1)

mark palmer
mark palmer il 30 Mar 2020
Modificato: mark palmer il 30 Mar 2020
Any quadrilateral, yes, or any 8, 12 or 16 etc point shape. For a diamond, it would be TL BL BR TR. The other solution to a diamond is also fine, makes no difference.

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by