find the area of a regular polygon circumscribed around a circle in python

To find the area of a regular polygon circumscribed around a circle, we can use the following formula:

area = (n * s**2) / (4 * tan(pi/n))

where n is the number of sides, s is the length of each side, pi is the mathematical constant pi, and tan is the tangent function from the math module.

To get s, we can use the formula:

s = 2 * r * sin(pi/n)

where r is the radius of the circumscribed circle.

Putting it all together, here's how we can implement this in Python:

main.py
from math import pi, tan, sin

def area_of_polygon_circumscribed_around_circle(n, r):
    s = 2 * r * sin(pi/n)
    area = (n * s**2) / (4 * tan(pi/n))
    return area
168 chars
7 lines

We can then call this function with the number of sides and radius of the circle, like so:

main.py
area = area_of_polygon_circumscribed_around_circle(6, 5)
print(area) # output: 64.9519052838329
96 chars
3 lines

This will give us the area of a regular hexagon circumscribed around a circle with a radius of 5.

gistlibby LogSnag