Find the corners of a deformed rectangle

geometry

Solution

Farthest point from the center will give you one corner. Farthest point from the first corner will give you another corner, which may be either adjacent or opposite to the first. Farthest point from the line between those two corners (a bit more math intensitive) will give you a third corner. I'd use distance from center as a tie breaker. For finding the 4th corner, it'll be the point outside the triangle formed by the first 3 corners you found, farthest from the nearest line between those corners.

This is a very time consuming way to do it, and I've never tried it, but it ought to work.

Problem

I am trying to make a program that automatically corrects the perspective of a rectangle. I have managed to get the silhouette of the rectangle, and have the code to correct the perspective, but I can't find the corners. The biggest problem is that, because it has been deformed, I can't use the following "code": ``` c1 = min(x), min(y) c2 = max(x), min(y) c3 = min(x), max(y) c4 = max(x), max(y) ``` This wouldn't work with this situation (X represents a corner): ``` X0000000000X .00000000000 ..X000000000 .....0000000 ........0000 ...........X ``` Does anyone know how to do this?

Original source

Related problems