0
$\begingroup$

I have the four coordinates of a rectangle in the format: (xi, yi). I want to find out which of the coordinates correspond to the top-left, top-right, bottom-left and bottom-right of the rectangle. Can someone help me in doing this? Any help is much appreciated. Thank you.

Edit: The rectangle can be a rotated rectangle. Is there any algorithm for this?

$\endgroup$
1
1
$\begingroup$

The $x$ coordinate tells you how far to the right of $(0,0)$ a point is - so the point with the lowest $x$ coordinate is the left most point.

Similarly, the $y$ coordinate tells you how far above $(0,0)$ the point is - the point with the lowest $y$-coordinate is the lowest point in terms of height. For example, the point $(-1,2)$ is to the left of and below the point $(1, 3)$.

Combining these two facts, which corner will be the bottom-left? Likewise for the other corners

$\endgroup$
1
  • $\begingroup$ Thanks for the help. Forgot to mention, The rectangle can be rotated also. In this case how can get the locations? $\endgroup$ – planet_pluto Aug 4 '19 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.