**The objective is to write the Python code to find the type of the polygon (Complex, Convex or Concave) from its vertices and also find the area and perimeter of Convex and Concave Polygon.**

In geometry, a polygon is a plane figure that is described by a finite number of straight line segments connected to form a closed shape. There are many types of Polygons. Let’s start with **Simple** and **Complex** polygons. Complex Polygons have intersecting line segments while in simple polygon there is no intersecting line segments as shown below:

Simple Polygons are further divided into **Convex** and **Concave** polygons. The simplest way to determine if a Polygon is Convex or Concave is to imagine two points inside the polygon. Observe if the line segment joining the two interior points intersects with any of the polygon side or not. If it doesn’t intersect with any Polygon side (for each possible pair of points inside polygon), then it is Convex Polygon. And if there is possibility of any pair of points inside the polygon such that the line segment joining those will intersect with any side of the polygon, then the polygon is Concave Polygon. See the difference in following figure:

Before starting this discussion, let’s first observe that area of a **Complex Polygon** is not possible to determine since there can be a few parts for which it cannot be determined whether those will be part of the area or not. See the following figure:

We will find Area and Perimeter of **Simple** (both Convex and Concave Polygons).

For perimeter, the calculations are quite simple as we just need to find the lengths of the line segments and sum them up. For the area, the first simple approach can be dividing the polygon into triangles and summing up the areas of all triangles. But this method is applicable only on Convex Polygons and for Concave Polygon it is not applicable as this approach might include some parts outside of the polygon.

**The detail is given in this video:**

Now we have to develop the algorithm to determine the Type of the Polygon where a Polygon is specified by its vertices. And then we need to find the area of both Convex and Concave Polygons.

Let’s first see how to determine the type of the Polygon:

- We should check for the intersection of Line Segments of the Polygon. If any intersection is found, the Polygon is Complex Polygon and otherwise it will be Convex or Concave.
- To differentiate between Convex and Concave polygons, we need to find the cross products of all adjacent line segments of the Polygon and observe the direction (inward or outward) of the cross product. If all cross products are directed into the plane or all are directed out of the plane, the Polygon will be Convex. And if they are both i.e. few into the plane and few out of it, it will be a Concave Polygon.

Finally, for the area of any simple polygon (Convex or Concave) we can use the **Shoelace Algorithm**.

**Please Subscribe:** Learning Orbis

**The detail of above-mentioned procedure can be found in this video:**

**And for the complete solution, you can watch this video:**

#python #programming #polygon

45.50 GEEK