Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Calculating borders of a rectangle

My question is a bit of definition related.

Let’s say we have got a rectangle with its top-left corner at (0,0) and width=100px height=200px. My question is: how we compute the last pixels that belong to the rectangle? Specifically I want to know the x coords of the left and right border and y coords of top and bottom border that contains pixels belonging to the rectangle.

I tried to simply left=origin x, right=origin x + width, top=origin y, bottom=origin y - height, but during tests I found out that when rectangles are next to each other the above equations results in pixels that belongs to more than one rectangle at once (they shouldn’t). So, I wish to know how to calculate them properly.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

enter image description here

In this figure,

  • Orange rect : (left,top) = (1,2), width=3, height=2
  • Green rect : (left,top) = (4,3), width=2, height=2

I think, this is the ordinal definition for pixel world.

In this example, no pixels belong to both.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading