How to find the top left corner of an arbitrary convex quadrilateral? I have 4 arbitrary points in 2D space. They are in an array, where they are guaranteed to be ordered counter-clockwise in relation to each other. How do I tell which of the points is the top left one?

 A: Two vertices belong to the set LEFT, and two to the set TOP (excepting colinear axial perpendicularites - but we can assume all the coordinate components are piecewise-distinct).
You want the intersection vertex, if it exists, which is not always the case (e.g. (1,0), (0,1), (10,9), (9,10)), in which case there is no TL coordinate.
We can make progress with the highest element of the LEFT set, or the leftmost element of the TOP set, which leaves two choices.
Alternatively, make an arbitrary 'north', and read the vertices anti-clockwise as N: TL, BL, BR, TR.
A: Here is my algorithm: name the vertices $A, B, C, D$ where $A$ is the leftmost and they are ordered clockwise (if there are several leftmost, choose the topmost of them to be $A$). Now let $X$ be the topmost of all the points. If $X$ is $A$ or $B$, then $TL=A$. If $X$ is $C$ or $D$ then $TL=B$. 
A: Can we agree that the top left corner is the first one met by a "sweeping line" with a $45°$ slope coming from above ?
Therefore, as the equation of such a line is $y-x=m$, it suffices to test the four quantities $y_k-x_k \ (k=1\cdots 4)$ for the four coordinates $(x_k,y_k)$ of the vertices. The highest value gives the winner vertex... of course with a possible "tie" if one of the sides has itself a $45°$ slope.
A: I ended up implementing the following algorithm:


*

*Determine the point with the greatest y-value. Call it P. This is one of your upper corners.

*Draw lines from P to both its neigbors. Take the endpoint of the line that has the shallower angle (closer to horizontal), and call it Q.

*If P's x-value is less than Q's x-value, then P is your top left vertex and Q is top-right. If P's x is greater than Q's, exactly the opposite.


Of course, this doesn't cover all of the cases, but some are simply impossible to solve due to ambiguities, and require special treatment anyway. This algorithm correctly covers all the real world cases I tried so far, and thus is "good enough" for me. If someone can come up with a more robust algorithm, perhaps with provisions for detecing ambiguous cases, that would be much appreciated.
