Convex polygon test

440 Views Asked by At

Let $P=P_1P_2\dots P_n$ be a simple polygon with $n \geq 3$ vertices $P_i$ and edges $P_iP_{i+1}$ (where $P_{n+1} = P_1$). We say that $P$ is convex if $P_j$ is to the left of the directed line $P_iP_{i+1}$ for all $j$ and all $i$. I believe it's true that actually, we only need $P_{i+2}$ is to the left of $P_iP_{i+1}$ for all $i$. But how do I rigorously prove this? The proof should use the simplicity of $P$, because this is not true for complex $P$.

Here, we define "point $R$ is to the left of directed line $PQ$" if the counterclockwise predicate $$ccw(P,Q,R) = (Q-P)_x (R - P)_y - (Q-P)_y(R-P)_x \geq 0$$ holds.

1

There are 1 best solutions below

2
On

The setup: order vertices anticlockwise. edges between adjacent vertices should be directed in such a way so as to move from a smaller number to a larger number. "left" and "right" are with respect to this direction.

The proof of the result you want:

This can be proved by induction on the number of vertices $n$. For $n = 3$ there is nothing to prove since every triangle is convex. Assume the result is true for $n-1$. Then, given a polygon with $n$ vertices which satisfies the condition that $P_{i+1}$ is to the left of the line $P_{i-1}P_i$ for all $i$, remove a chosen vertex $v$ between vertices $P_k$ and $P_{k+2}$, and notice that this gives rise to a $n-1$ polygon with the same property. By our inductive hypothesis, this $n-1$ polygon is convex. Now we put $v$ back in, and the original condition says that $v$ is to the left of $P_{k-1}P_k$ and that $P_{k+2}$ is to the left of $P_kv$, which implies that our polygon when we put $v$ back in is convex.