Determine coordinates of rotated rectangle

Posted by MathieuK on Stack Overflow See other posts from Stack Overflow or by MathieuK
Published on 2010-04-10T11:11:41Z Indexed on 2010/04/10 11:13 UTC
Read the original article Hit count: 213

I'm creating an utility application that should detect and report the coordinates of the corners of a transparent rectangle (alpha=0) within an image.

So far, I've set up a system with Javascript + Canvas that displays the image and starts a floodfill-like operation when I click inside the transparent rectangle in the image. It correctly determines the bounding box of the floodfill operation and as such can provide me the correct coordinates.

Here's my implementation so-far: http://www.scriptorama.nl/image/ (works in recent Firefox / Safari ).

However, the bounding box approach breaks down then the transparent rectangle is rotated (CW or CCW) as the resulting bounding box no longer properly represents the proper width and height. I've tried to come up with a few alternatives to detect to corners, but have not been able to think up a proper solution.

So, does anyone have any suggestions on how I might approach this so I can properly detect the coordinates of 4 corners of the rotated rectangle?

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about image-processing