Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Area of the Largest Triangle inscribed in a Hexagon in C++
In this problem, our task is to find the area of the largest triangle that can be inscribed in a regular hexagon. Each side of the hexagon and triangle is of length a and b, respectively.

Area of the Largest Triangle Inscribed in a Hexagon
You can calculate the area of the largest triangle inscribed in a regular hexagon using the following formula:
$$ Area\ of\ triangle\ inside\ hexagon\ = \frac{3\sqrt{3}}{4} \cdot a^2 $$Derivation
The first step is to establish a relation between a and b, as the value of a(side of the hexagon) is given.
In triangle EXF, EF<sup>2</sup> = FX<sup>2</sup> + XE<sup>2</sup> (Using Pythagorean theorem) => a<sup>2</sup> = (a/2)<sup>2</sup> + (b/2)<sup>2</sup> (X is perpendicular bisector of AE and OF) => b = a * sqrt(3)
Now, we need the height of the triangle AEC.
Height of equilateral triangle = (b * sqrt(3)) / 2
Calculating the area of the triangle (AEC) inscribed inside a hexagon:
Area of triangle = (1/2) * base * height Area = (1/2) * b * ((b * sqrt(3)) / 2) Substituting b = a * sqrt(3): Area = (1/2) * (a * sqrt(3)) * ((a * sqrt(3)) / 2) <strong>Area = (3 * sqrt(3) / 4) * a^2</strong>
Let's see some input-output scenarios for a better understanding:
Scenario 1
<strong>Input:</strong> a = 6 <strong>Output:</strong> Area = 46.765 <strong>Explanation:</strong> Using the formula: Area = (3 * sqrt(3) / 4) * a^2 Area = (3 * sqrt(3) / 4) * 6^2 Area = (3 * 1.732 / 4) * 36 Area = 46.765
Scenario 2
<strong>Input:</strong> a = 10 <strong>Output:</strong> Area = 129.903 <strong>Explanation:</strong> Area = (3 * sqrt(3) / 4) * 10^2 Area = (3 * 1.732 / 4) * 100 Area = 129.903
C++ Program for Area of Largest Triangle in Hexagon
To calculate the area of the Largest Triangle inscribed in a Hexagon using a C++ program, we just need to implement the above-discussed formula as shown below:
#include <iostream>
#include <cmath>
using namespace std;
float maxTriangleArea(float a) {
if (a < 0) // if value is negative it is invalid
return -1;
float area = (3 * sqrt(3) * pow(a, 2)) / 4;
return area;
}
int main() {
float a = 6;
cout << "Side of hexagon is: " << a << endl;
cout << "Area of largest triangle is: " << maxTriangleArea(a);
}
The output of the above code is as follows:
Side of hexagon is: 6 Area of largest triangle is: 46.7654
