The Wayback Machine - https://web.archive.org/web/20240828111600/https://www.geeksforgeeks.org/area-of-a-n-sided-regular-polygon-with-given-side-length/
Open In App

Area of a n-sided regular polygon with given side length

Last Updated : 25 Jun, 2022
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow
Solve Problem
Easy
10.82%
874

Given a regular polygon of N sides with side length a. The task is to find the area of the polygon. 
Examples: 
 

Input : N = 6, a = 9
Output : 210.444

Input : N = 7, a = 8
Output : 232.571

 

 

Approach: In the figure above, we see the polygon can be divided into N equal triangles. Looking into one of the triangles, we see that the whole angle at the center can be divided into = 360/N
So, angle t = 180/n 
Now, tan(t) = a/2*h
So, h = a/(2*tan(t))
Area of each triangle = (base * height)/2 = a * a/(4*tan(t)) 
So, area of the polygon, 
 

A = n * (area of one triangle) = a2 * n/(4tan t)

Below is the implementation of the above approach: 
 

C++




// C++ Program to find the area of a regular
// polygon with given side length
 
#include <bits/stdc++.h>
using namespace std;
 
// Function to find the area
// of a regular polygon
float polyarea(float n, float a)
{
    // Side and side length cannot be negative
    if (a < 0 && n < 0)
        return -1;
 
    // Area
    // degree converted to radians
    float A = (a * a * n) / (4 * tan((180 / n) * 3.14159 / 180));
 
    return A;
}
 
// Driver code
int main()
{
    float a = 9, n = 6;
 
    cout << polyarea(n, a) << endl;
 
    return 0;
}


Java




// Java  Program to find the area of a regular
// polygon with given side length
 
import java.io.*;
 
class GFG {
   
 
// Function to find the area
// of a regular polygon
static float polyarea(float n, float a)
{
    // Side and side length cannot be negative
    if (a < 0 && n < 0)
        return -1;
 
    // Area
    // degree converted to radians
    float A = (a * a * n) /(float) (4 * Math.tan((180 / n) * 3.14159 / 180));
 
    return A;
}
 
// Driver code
 
    public static void main (String[] args) {
    float a = 9, n = 6;
 
    System.out.println( polyarea(n, a));
    }
}
// This code is contributed by inder_verma..


Python3




# Python 3 Program to find the area
# of a regular polygon with given
# side length
from math import tan
 
# Function to find the area of a
# regular polygon
def polyarea(n, a):
     
    # Side and side length cannot
    # be negative
    if (a < 0 and n < 0):
        return -1
 
    # Area degree converted to radians
    A = (a * a * n) / (4 * tan((180 / n) *
                      3.14159 / 180))
 
    return A
 
# Driver code
if __name__ == '__main__':
    a = 9
    n = 6
 
    print('{0:.6}'.format(polyarea(n, a)))
 
# This code is contributed by
# Shashank_sharma


C#




// C# Program to find the area of a regular
// polygon with given side length
using System;
 
class GFG
{
 
// Function to find the area
// of a regular polygon
static float polyarea(float n, float a)
{
    // Side and side length cannot be negative
    if (a < 0 && n < 0)
        return -1;
 
    // Area
    // degree converted to radians
    float A = (a * a * n) / (float)(4 * Math.Tan((180 / n) *
                                           3.14159 / 180));
 
    return A;
}
 
// Driver code
public static void Main ()
{
    float a = 9, n = 6;
     
    Console.WriteLine(polyarea(n, a));
}
}
 
// This code is contributed
// by Akanksha Rai


PHP




<?php
// PHP Program to find the area of a regular
// polygon with given side length
 
// Function to find the area
// of a regular polygon
function polyarea($n, $a)
{
    // Side and side length cannot
    // be negative
    if ($a < 0 && $n < 0)
        return -1;
 
    // Area
    // degree converted to radians
    $A = ($a * $a * $n) / (4 * tan((180 / $n) *
                              3.14159 / 180));
 
    return $A;
}
 
// Driver code
$a = 9 ;
$n = 6 ;
 
echo round(polyarea($n, $a), 3);
 
// This code is contributed by Ryuga
?>


Javascript




<script>
// javascript  Program to find the area of a regular
// polygon with given side length
 
// Function to find the area
// of a regular polygon
function polyarea(n , a)
{
 
    // Side and side length cannot be negative
    if (a < 0 && n < 0)
        return -1;
 
    // Area
    // degree converted to radians
    var A = (a * a * n) / (4 * Math.tan((180 / n) * 3.14159 / 180));
 
    return A;
}
 
// Driver code
var a = 9, n = 6;
document.write( polyarea(n, a).toFixed(5));
 
// This code contributed by Princi Singh
</script>


Output: 

210.444

 

Time Complexity: O(1)

Auxiliary Space: O(1)



Similar Reads

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 given 8-sided polygon as shown below: Input: N = 3Outp
3 min read
Side of a regular n-sided polygon circumscribed in a circle
Given two integers r and n where n is the number of sides of a regular polygon and r is the radius of the circle this polygon is circumscribed in. The task is to find the length of the side of polygon. Examples: Input: n = 5, r = 11 Output: 12.9256Input: n = 3, r = 5 Output: 8.6576 Approach: Consider the image above and let angle AOB be theta then
4 min read
Area of a n-sided regular polygon with given Radius
Given a regular polygon of N sides with radius(distance from the center to any vertex) R. The task is to find the area of the polygon.Examples: Input : r = 9, N = 6 Output : 210.444 Input : r = 8, N = 7 Output : 232.571 In the figure, we see that the polygon can be divided into N equal triangles.Looking into one of the triangles, we see that the wh
4 min read
Program to find Area of Triangle inscribed in N-sided Regular Polygon
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 tr
6 min read
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 we clearly see that the angle x is 30 degree so th
5 min read
Ratio of area of two nested polygons formed by connecting midpoints of sides of a regular N-sided polygon
Given an N-sided polygon, the task is to find the ratio of the area of the Nth to (N + 1)th N-sided regular nested polygons generated by joining the midpoints of the sides of the original polygon. Examples : Input: N = 3Output: 4.000000Explanation: Ratio of the length of the sides formed by joining the mid-points of the triangle with the length of
4 min read
Length of Diagonal of a n-sided regular polygon
Given a n-sided regular polygon of side length a.The task is to find the length of it's diagonal.Examples: Input: a = 9, n = 10 Output: 17.119 Input: a = 4, n = 5 Output: 6.47213 Approach: We know that the sum of interior angles of a polygon = (n – 2) * 180 where, n is the no. of sides in the polygon. So, each interior angle = (n – 2) * 180/n Now,
4 min read
Angle between 3 given vertices in a n-sided regular polygon
Given a n-sided regular polygon and three vertices a1, a2 and a3, the task is to find the angle suspended at vertex a1 by vertex a2 and vertex a3. Examples: Input: n = 6, a1 = 1, a2 = 2, a3 = 4 Output: 90 Input: n = 5, a1 = 1, a2 = 2, a3 = 5 Output: 36 Approach: The angle subtended by an edge on the center of n sided regular polygon is 360/n.The an
6 min read
Number of occurrences of a given angle formed using 3 vertices of a n-sided regular polygon
Given an n-sided regular polygon and an angle ?, the task is to find number of occurrences of angle ( Ai, Aj, Ak ) = ? ( i &lt; j &lt; k) in a regular n-gon (regular polygon with n vertices) with vertices marked as A1, A2, ..., An.Examples: Input: n = 4, ang = 90 Output: 4 Input: n = 6, ang = 50 Output: 0 Approach: First we check whether such an an
6 min read
Number of triangles formed by joining vertices of n-sided polygon with one side common
Given N-sided polygon we need to find the number of triangles formed by joining the vertices of the given polygon with exactly one side being common.Examples: Input : 6 Output : 12 The image below is of a triangle forming inside a Hexagon by joining vertices as shown above. The two triangles formed has one side (AB) common with that of a polygon.It
4 min read
Apothem of a n-sided regular polygon
Given here the side length a of a regular n-sided polygon, the task is to find the length of its Apothem. Apothem is the line drawn from the center of the polygon that is perpendicular to one of its sides. Examples: Input a = 9, n = 6 Output: 7.79424 Input: a = 8, n = 7 Output: 8.30609 Approach: In the figure, we see the polygon can be divided into
4 min read
Determine the position of the third person on regular N sided polygon
Given 'N' which represent the regular N sided polygon. Two children are standing on the vertex 'A' and 'B' of this Regular N sided polygon. The task is to determine the number of that vertex another person should stand on so that the sum of the minimum jumps required to reach A and minimum jumps required to reach B is minimized. Note: The vertices
6 min read
Central angle of a N sided Regular Polygon
Given an integer N representing N sided regular polygon, the task is to find the angle made by the sides on the centre of the polygon that is the central angle. The central angle is the angle formed by the two vertices forming an edge and the centre. Examples: Input: N = 6 Output: 60 Explanation: The polygon is a hexagon with an angle 60 degree. In
3 min read
Find the angle of Rotational Symmetry of an N-sided regular polygon
Given an integer N which is the number of sides of a regular polygon. The task is to find the smallest angle of rotation such that the generated regular polygons have a similar position and dimensions, i.e. the new rotated polygon is in symmetry with the initial one. A shape is said to have a rotation symmetry if there exists a rotation in the rang
4 min read
Find three vertices in an N-sided regular polygon such that the angle subtended at a vertex by two other vertices is closest to A
Given an N-sided regular convex polygon and an angle A in degrees, the task is to find any 3 vertices i, j, and k, such that the angle subtended at vertex j by vertex i and k is closest to A. Note: Each vertex is numbered from 1 to N in an anticlockwise direction starting from any vertex. Examples: Input: N = 3, A = 15Output: 2 1 3Explanation:The g
7 min read
Find the length of Kth N-sided polygon formed by given operations
Given an integer L, representing the side length of an N-sided regular polygon and integer K, the task is to find the side length of the Kth N-sided regular polygon formed inside the (K - 1)th regular polygon by connecting midpoints of the sides of the (K - 1)th polygon. Examples: Input: N = 3, L = 6, K = 2Output: 3 Input: N = 5, L = 21, K = 7Outpu
5 min read
Area of Triangle using Side-Angle-Side (length of two sides and the included angle)
Given two integers A, B representing the length of two sides of a triangle and an integer K representing the angle between them in radian, the task is to calculate the area of the triangle from the given information.Examples: Input: a = 9, b = 12, K = 2 Output: 49.1 Explanation: Area of triangle = 1 / 2 * (9 * 12 * Sin 2) = 35.12Input: A = 2, B = 4
4 min read
Minimum side of square embedded in Regular polygon with N sides
Given an even number N which represents the number of sides of a regular polygon with N vertices, the task is to find the square of the minimum size such that given Polygon can completely embed in the square. A Polygon is a convex figure and has equal sides and equal angles. All sides have length 1. Embedding: Place Polygon in the square in such wa
8 min read
Check if an N-sided Polygon is possible from N given angles
Given an array arr[] of N elements, where each element represents an angle(in degrees) of a polygon, the task is to check whether it is possible to make an N-sided polygon with all the given angles or not. If it is possible then print Yes else print No. Examples: Input: N = 3, arr[] = {60, 60, 60}Output: YesExplanation: There exists a triangle(i.e.
4 min read
Probability that the pieces of a broken stick form a n sided polygon
We have a stick of length L. The stick got broken at (n-1) randomly chosen points (lengths of parts can be non-integer or floating point numbers also) so we get n parts. We need to find the probability that these n pieces can form a n sided polygon. Examples: Input : L = 5 n = 3 Output : 0.25 We need to cut rope of length 5 into three parts. First
4 min read
Number of triangles formed by joining vertices of n-sided polygon with two common sides and no common sides
Given N-sided polygon we need to find the total number of triangles formed by joining the vertices of the given polygon with exactly two sides being common and no side being common.Examples: Input : N = 6 Output : 6 2 The image below is of a triangle forming inside a Hexagon by joining vertices as shown above. The triangle formed has two sides (AB
5 min read
Number of cycles formed by joining vertices of n sided polygon at the center
Given an N-sided regular polygon, we have connected all the vertices at the center of the polygon, thus dividing the polygon into N equal parts. Our task is to the Count of the total number of cycles in the polygon.Note: A Cycle is a closed-loop starting and ending on same point.Examples: Input: N = 3 Output: 7 Explanation: When a 3 sided polygon i
5 min read
Find the vertex diagonally opposite to the vertex M from an N-sided polygon
Given two integers N and M, the task is to find the vertex diagonally opposite to the Mth vertex of an N-sided polygon. Examples: Input: N = 6, M = 2 Output: 5 Explanation: It can be observed from the image above that the vertex opposite to vertex 5 is 2. Input: N = 8, M = 5 Output: 1 Explanation: It can be observed from the image above that the ve
3 min read
Find number of diagonals in n sided convex polygon
Given n &gt; 3, find number of diagonals in n sided convex polygon.According to Wikipedia, In geometry, a diagonal is a line segment joining two vertices of a polygon or polyhedron, when those vertices are not on the same edge. Informally, any sloping line is called diagonal. Examples :  Input : 5Output : 5Explanation: Five possible diagonals are :
3 min read
Check if given polygon is a convex polygon or not
Given a 2D array point[][] with each row of the form {X, Y}, representing the co-ordinates of a polygon in either clockwise or counterclockwise sequence, the task is to check if the polygon is a convex polygon or not. If found to be true, then print "Yes" . Otherwise, print "No". In a convex polygon, all interior angles are less than or equal to 18
9 min read
Find the area of rhombus from given Angle and Side length
Given two integers A and X, denoting the length of a side of a rhombus and an angle respectively, the task is to find the area of the rhombus. A rhombus is a quadrilateral having 4 sides of equal length, in which both the opposite sides are parallel, and opposite angles are equal. Examples: Input: A = 4, X = 60Output: 13.86 Input: A = 4, X = 30Outp
3 min read
Arrange rods to make K side Polygon
Given an array of rods[] of size N and an integer value K (3 &lt;= K &lt;= 6), where rods[i] (1 &lt;= rods[i] &lt;= 108) is the length of the ith rod(1 &lt;= rods.length &lt;= 10), the task is to check if it is possible to arrange all the rods to make a regular polygon of K sides without breaking any rod. Examples: Input: rods[] = {1, 1, 2, 2, 2},
10 min read
Program to find the Interior and Exterior Angle of a Regular Polygon
Given the number of sides n of a regular polygon. The task is to find out the Interior angle and Exterior angle of the polygon.Examples: Input : n = 6 Output : Interior angle: 120 Exterior angle: 60 Input : n = 10 Output: Interior angle: 144 Exterior angle: 36 Interior angle: The angle between two adjacent sides inside the polygon is known as the I
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.02487 Approach: A regular n-gon divides the circle into n pieces, so the central angle of the triangle is a full circle divided by n: 360 deg/n. Applying the law of
4 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 Output: Perimeter : 12.5 Since the sides are 5,
5 min read