Program to find Area of Triangle inscribed in N-sided Regular Polygon
Last Updated :
04 Jun, 2022
Given the triangle inscribed in an N-sided regular polygon with given side length, formed using any 3 vertices of the polygon, the task is to find the area of this triangle.
Examples:
Input: N = 6, side = 10
Output: 129.904
Input: N = 8, side = 5
Output: 45.2665
Approach: Consider the 1st example:
- Given is a 6 sided regular polygon ABCDEF with a triangle AEC inscribed in it.
- As it can be seen, the triangle divides given polygon into 6 equal triangular areas, where the point of intersection of triangle AEC is the centroid of the triangle.

- Find the area of the regular polygon. Area of the regular polygon can be calculated with the help of formula (A*P)/2 where P is the perimeter of that polygon and A is apothem of that polygon.
- Area of each of the triangulated part will be (TriangulatedArea = Area of N sided regular polygon / N) from the law of symmetry.
- Since the Triangle ACE comprises of 3 out of 6 in it, So the area of triangle ACE will be (3 * TriangulatedArea)
- Therefore, in general, if there is an N-sided regular polygon with area A, the area of a triangle inscribed in it will be (A/N)*3.
Below is the implementation of the above approach:
C++
// C++ Program to find the area of a triangle
// inscribed in N-sided regular polygon
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
// Function to find the area of the polygon
double area_of_regular_polygon(double n, double len)
{
// area of a regular polygon with N sides
// and side length len
double P = (len * n);
double A
= len
/ (2 * tan((180 / n)
* 3.14159 / 180));
double area = (P * A) / 2;
return area;
}
// Function to find the area of a triangle
double area_of_triangle_inscribed(double n, double len)
{
double area = area_of_regular_polygon(n, len);
// area of one triangle
// in an N-sided regular polygon
double triangle = area / n;
// area of inscribed triangle
double ins_tri = (triangle * 3);
return ins_tri;
}
// Driver code
int main()
{
double n = 6, len = 10;
cout << area_of_triangle_inscribed(n, len)
<< endl;
return 0;
}
Java
// Java Program to find the area of a triangle
// inscribed in N-sided regular polygon
import java.util.*;
class GFG
{
// Function to find the area of the polygon
static double area_of_regular_polygon(double n,
double len)
{
// area of a regular polygon with N sides
// and side length len
double P = (len * n);
double A = len / (2 * Math.tan((180 / n) *
3.14159 / 180));
double area = (P * A) / 2;
return area;
}
// Function to find the area of a triangle
static double area_of_triangle_inscribed(double n,
double len)
{
double area = area_of_regular_polygon(n, len);
// area of one triangle
// in an N-sided regular polygon
double triangle = area / n;
// area of inscribed triangle
double ins_tri = (triangle * 3);
return ins_tri;
}
// Driver code
static public void main(String[] arg)
{
double n = 6, len = 10;
System.out.printf("%.3f",
area_of_triangle_inscribed(n, len));
}
}
// This code is contributed by PrinciRaj1992
Python3
# Python3 Program to find the area
# of a triangle inscribed in
# N-sided regular polygon
import math
# Function to find the area of the polygon
def area_of_regular_polygon(n, len):
# area of a regular polygon with
# N sides and side length len
P = (len * n);
A = len / (2 * math.tan((180 / n) *
3.14159 / 180))
area = (P * A) / 2
return area
# Function to find the area of a triangle
def area_of_triangle_inscribed(n, len):
area = area_of_regular_polygon(n, len)
# area of one triangle
# in an N-sided regular polygon
triangle = area / n
# area of inscribed triangle
ins_tri = (triangle * 3);
return ins_tri
# Driver code
n = 6
len = 10
print(round(area_of_triangle_inscribed(n, len), 3))
# This code is contributed by divyamohan
C#
// C# Program to find the area of a triangle
// inscribed in N-sided regular polygon
using System;
class GFG
{
// Function to find the area of the polygon
static double area_of_regular_polygon(double n,
double len)
{
// area of a regular polygon with N sides
// and side length len
double P = (len * n);
double A = len / (2 * Math.Tan((180 / n) *
3.14159 / 180));
double area = (P * A) / 2;
return area;
}
// Function to find the area of a triangle
static double area_of_triangle_inscribed(double n,
double len)
{
double area = area_of_regular_polygon(n, len);
// area of one triangle
// in an N-sided regular polygon
double triangle = area / n;
// area of inscribed triangle
double ins_tri = (triangle * 3);
return ins_tri;
}
// Driver code
static public void Main(String[] arg)
{
double n = 6, len = 10;
Console.Write("{0:F3}",
area_of_triangle_inscribed(n, len));
}
}
// This code is contributed by PrinciRaj1992
JavaScript
<script>
// javascript Program to find the area of a triangle
// inscribed in N-sided regular polygon
// Function to find the area of the polygon
function area_of_regular_polygon(n, len)
{
// area of a regular polygon with N sides
// and side length len
let P = (len * n);
let A
= len
/ (2 * Math.tan((180 / n)
* 3.14159 / 180));
let area = (P * A) / 2;
return area;
}
// Function to find the area of a triangle
function area_of_triangle_inscribed( n, len)
{
let area = area_of_regular_polygon(n, len);
// area of one triangle
// in an N-sided regular polygon
let triangle = area / n;
// area of inscribed triangle
let ins_tri = (triangle * 3);
return ins_tri;
}
// Driver code
let n = 6, len = 10;
document.write( area_of_triangle_inscribed(n, len).toFixed(3));
// This code is contributed by todaysgaurav
</script>
Time Complexity: O(1), the code will run in a constant time.
Auxiliary Space: O(1), no extra space is required, so it is a constant.
Similar Reads
Area of largest Circle inscribe in N-sided Regular polygon Given a regular polygon of N sides with side length a. The task is to find the area of the Circle which inscribed in the polygon. Note : This problem is mixed version of This and This Examples: Input: N = 6, a = 4 Output: 37.6801 Explanation: In this, the polygon have 6 faces and as we see in fig.1
5 min read
Polygon with maximum sides that can be inscribed in an N-sided regular polygon Given a regular polygon of N sides, the task is to find the maximum sided polygon that can be inscribed inside the given polygon by joining non-adjacent vertices. Print -1, if no such polygon exist. Examples: Input: N = 8Output: 4Explanation:At most a 4 sided polygon can be inscribed inside the give
3 min read
Program to find the Perimeter of a Regular Polygon Given the number of sides 'n' and the length of side 's' of a regular polygon, the task is to find out the Perimeter of this polygon. Examples: Input: n = 7, s = 10 Output: Perimeter : 70 Since the sides are 7, Hence the given polygon is Heptagon. Therefore. Perimeter = 7*10 = 70 Input: n = 5, s = 2
5 min read
Program to Find the Incenter of a Triangle Given the vertices of a triangle and length of its sides. A circle is inscribed in a triangle. The task is to find the incenter of a triangle.Examples: Input: A(2, 2), B(1, 1), C(3, 1) Output: (2, 1.5) Input: A(3, 3), B(1, 2), C(2, 2) Output: (2.5, 2.83) Approach: The center of the circle that touch
4 min read
Program to find the Circumcircle of any regular polygon Given a n-sided polygon with side length a. The task is to find the area of the circumcircle of the polygon.Examples:Input: n = 10, a = 3 Output: 1.99737Input: n = 5, a = 6 Output: 3.02487Approach: A regular n-gon divides the circle into n pieces, so the central angle of the triangle is a full circl
4 min read