# How to Calculate the Area of a Regular N Sides Polygon Inside a Circle of Radius R in Python

• Home /
• Blog Posts /
• How to Calculate the area of a regular N sides polygon inside a circle of radius R in Python

## The challenge

Write the following function:

``````def area_of_polygon_inside_circle(circle_radius, number_of_sides):
``````

It should calculate the area of a regular polygon of `numberOfSides``number-of-sides`, or `number_of_sides` sides inside a circle of radius `circleRadius``circle-radius`, or `circle_radius` which passes through all the vertices of the polygon (such a circle is called circumscribed circle or circumcircle). The answer should be a number rounded to 3 decimal places.

Input/Output Examples

``````area_of_polygon_inside_circle(3, 3) # returns 11.691
area_of_polygon_inside_circle(5.8, 7) # returns 92.053
area_of_polygon_inside_circle(4, 5) # returns 38.042
``````

## The solution in Python code

Option 1:

``````from math import sin, pi

def area_of_polygon_inside_circle(r, n):
return round(0.5 * n * r ** 2 * sin(2 * pi / n), 3)
``````

Option 2:

``````import math
s = number_of_sides
a = (s * (r ** 2) * math.sin(2*math.pi/s))/2
return round(a, 3)
``````

Option 3:

``````from math import sin,cos,radians
``````test.describe('Example Tests')