Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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!
  1 Kommentar
Tommy
Tommy am 30 Mär. 2020
Do you mean any quadrilateral? And what should happen in the case of a diamond? e.g. [2 2; 3 3; 2 4; 1 3]

Melden Sie sich an, um zu kommentieren.

Antworten (1)

mark palmer
mark palmer am 30 Mär. 2020
Bearbeitet: mark palmer am 30 Mär. 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.

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by