The problem
Write the next operate:
def area_of_polygon_inside_circle(circle_radius, number_of_sides):
It ought to calculate the realm of an everyday polygon of numberOfSides
, number-of-sides
, or number_of_sides
sides inside a circle of radius circleRadius
, circle-radius
, or circle_radius
which passes by means of all of the vertices of the polygon (such a circle known as circumscribed circle or circumcircle). The reply must be a quantity rounded to three decimal locations.
Enter/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 answer in Python code
Choice 1:
from math import sin, pi
def area_of_polygon_inside_circle(r, n):
return spherical(0.5 * n * r ** 2 * sin(2 * pi / n), 3)
Choice 2:
import math
def area_of_polygon_inside_circle(circle_radius, number_of_sides):
r = circle_radius
s = number_of_sides
a = (s * (r ** 2) * math.sin(2*math.pi/s))/2
return spherical(a, 3)
Choice 3:
from math import sin,cos,radians
def area_of_polygon_inside_circle(circle_radius, number_of_sides):
angle = radians(360/(number_of_sides*2))
reverse = circle_radius*sin(angle)
adjoining = circle_radius*cos(angle)
return spherical(adjoining*reverse*number_of_sides,3)
Check instances to validate our resolution
check.describe('Instance Checks')
check.it('ex1')
check.assert_equals(area_of_polygon_inside_circle(3, 3), 11.691)
check.it('ex2')
check.assert_equals(area_of_polygon_inside_circle(2, 4), 8)
check.it('ex3')
check.assert_equals(area_of_polygon_inside_circle(2.5, 5), 14.86)