- Practice
- Functional Programming
- Recursion
- Convex Hull

# Convex Hull

# Convex Hull

*Contributed by Abhiranjan Kumar*

Convex Hull of a set of points, in 2D plane, is a convex polygon with minimum area such that each point lies either on the boundary of polygon or inside it.

Let's consider a 2D plane, where we plug pegs at the points mentioned. We enclose all the pegs with a elastic band and then release it to take its shape. The closed structure formed by elastic band is similar to that of convex hull.

In the above figure, convex hull of the points, represented as dots, is the polygon formed by blue line.

**Tasks**

Given a set of *N* points, Find the perimeter of the convex hull for the points.

**Input Format**

First line of input will contain a integer, *N*, number of points. Then follow *N* lines where each line contains the coordinate, *x _{i} y_{i}*, of

*i*point.

^{th}**Output Format**

Print the perimeter of convex hull for the given set of points. An error margin of +/- 0.2 is acceptable.

**Constraints**

3 <= N <= 10^{4}

0 <= x_{i}, y_{i} <= 10^{4}

There exists, at least, three points which are non-colinear.

**Sample Input**

```
6
1 1
2 5
3 3
5 3
3 2
2 2
```

**Sample Output**

```
12.2
```

**Explanation**

For the given set of points in sample input, the convex hull is formed by the triangle whose vertices are given by `(1, 1), (2, 5), (5, 3)`

. Here perimeter of the hull is 12.200792856.