سؤال

I have functions to calculate area, perimeter and side of the polygon inscribed on circle, but I'd like to find out similar general way to calculate same properties of the polygons drawn around the circle.

Inscribed

# Area of an equal sided polygon with given radius and number of sides
def polygon_area(r, n):
    return ((n*pow(r, 2))/2)*sin(2*pi/n)

# Perimeter of an equal sided polygon with given radius and number of sides
def polygon_perimeter(r, n):
    return 2*n*r*sin(pi/n)

# Side length of an equal sided polygon with given radius and number of sides
def polygon_side(r, n):
    return polygon_perimeter(r, n)/n

Answer probably has something to do with apothem, like on this picture. Problem is, that I know only radius of the circle:

inner outer circle

هل كانت مفيدة؟

المحلول

You just need to use the factor of the apothem (apothem = radius * cos(pi/n)) in your existing formulas (which I did not check):

# Area of an equal sided polygon with given radius and number of sides
def polygon_area_outer(r, n):
    return n * r**2 / 2 * sin(2*pi/n) / cos(pi/n)**2

# Side length of an equal sided polygon with given radius and number of sides
def polygon_side_outer(r, n):
    return 2 * r * sin(pi/n) / cos(pi/n)

# Perimeter of an equal sided polygon with given radius and number of sides
def polygon_perimeter_outer(r, n):
    return polygon_side_outer(r, n) * n

I changed the order of your functions to base the perimeter on the side (not vice versa) to avoid multiplying and then diving by n when computing the polygon_side length.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top