I Would like to check if a set of N points describe a convex polygon or not
I was wondering if there is a good algorithm for that ?
Here is some approaches I thought of:
1.Convex Hull algorithm :
If the set is equal to his convex hull then it's convex. The complexity of such algorithm are O(n*LN(N)). But I had the feeling it was like breaking a butterfly upon a wheel.
3.Looking at the angles :
Then I thought of checking if the angles of 2 consecutive vectors never exceed 180°. But since my points are not ordered I need to check all the combinations of 3 consecutives points and that makes like an O(n3) complexity.(There should be a way to do better than that)
I try selecting points from right to left for example but the results are not always the one expected:
For example in this case I find a convex shape if I take from left to right:
So for this solution I might need a good algorithm to select the points.
3. looking at the barycenter :
I think that checking if the baricenter of all 3 consecutives point is inside the shape will tell me if the shape is convex of not.
Here is what I mean (G is the baricenter of each triangle):
for this solution I can select the points from left to right without problems. if the complexity of checking if G is in the shape is O(N) then the overall complexity would be somthing like O(N2).
Can you please advise me on a good algorithm to solve this problem or improve the solutions I am thinking of
Thanks in advance
N
points (are they ordered?) then you can't get anything better thanN*log(N)
. If I can come up with a proof, I'll be happy to share it with you, but right now, it's more a feeling thant a proof. – Oxidate