How to determine which type of quadrilateral is by giving the four points of the quadrilateral?

I am developing a crop image tool. After I get the coordinates of the four points, I want to judge whether the quadrilateral is convex quadrilateral.

But I am not good at geometry, so I want to ask for your help.

I hope that the answer can be easy to understand, you can think I know little about geometry. Something like a process.("1. Calculate the angle 2. Whether the degree of the four corners is equal to ...")

Sample image:

Sample Image

Related:

convex quadrilateral test


Solution 1:

This is a computational geometry problem. Any method without trials and errors of actual data tend to be buggy. So I'll only talk about essential ideas here.

The essential idea is to use cross products to distinguish left-turns and right-turns. If at every corner the turning direction is the same (either all left-turn or all right-turn), and the sum of exterior angles equals $360^\circ$ (rather than other multiples of $360^\circ$), it's convex. Otherwise, the $n$-gon may either be non-convex or self-crossing.

In case the order of vertices is known, the above procedure should work. In case the order is not known, use the convex hull algorithm and then see if all vertices are on the convex hull. If yes, that means at least there exists an order of vertices that makes the $n$-gon convex. If no, then there isn't an order of vertices that makes the $n$-gon convex.