You are given the length of the diagonal of a hexagon, d. Your task is to find the area of that hexagon.
Input : 5 Output : Area of Hexagon: 16.238 Input : 10 Output : Area of Hexagon: 64.9519
Hexagon is a regular polygon having six equal sides and all equal angles. The interior angles of Hexagon are of 120 degrees each and the sum of all angles of a Hexagon is 720 degrees.
Let d be the diagonal of Hexagon, then the formula to find the area of Hexagon given by
How does above formula work?
We know that area of hexagon with side length a = (3 √3(a)2 ) / 2. Since all sides are of same size and angle is 120 degree, d = 2a or a = d/2. After putting this value, we get area as (3 √3(d)2 ) / 8.
Below is the implementation .
Area of Hexagon: 64.952
Time Complexity: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.