Convex Polygons
11 Oct 2023
§ Statement
Determining if is a Convex Polygon
Suppose we are given the points when connected in the given order yields a closed polygon
How can we determine whether is closed, if so, it is convex?
§ Solution
A necessary and sufficient condition for whether is a polygon is for the interior angles summing to , where is the number of edges; all polygons, convex or concave, have this property.
Next, if convex, then every pair of edges must turn in the same direction.
The direction of turning can be found by using the determinant definition for the area of a triangle,
if the sign of the area does not match for all , then we reject and say that it is not a convex polygon.
Next, we compute the interior angles of each pair of edges formed by points and .
To do this, we define two vectors and , then the angle can be found by
Therefore, if the sum of interior angles satisfies
then we accept and say that it is a convex polygon; otherwise, we reject .
§ Algorithm
Detecting a Convex Polygon
- # Input: Set of points with ordering
- # Output: Determination of polygon is
CONVEX
,NOT_CONVEX
, orINVALID
- # Note:
NOT_CONVEX
CONCAVE
; it indicates a change in winding order - # (i.e. anticlockwise to clockwise, or vice versa).
- # It is a trivial modification to check if is
CONCAVE
- function DetectConvex()
-
if then
- return
INVALID
- return
-
-
-
for all in do
- Get vertices from
sign
- if
direction
is undefined thendirection
sign
- if
sign
<>direction
then- return
NOT_CONVEX
- return
-
-
if <> then
- return
INVALID
- return
-
-
return
CONVEX
-
Complexity Analysis
This method has complexity, as we iterate through each point once per step and the computations in each iteration are all constant constant with respect to the input .