Polygon area, perimeter and side length around the circle with python

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.

落款

# 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:


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.

链接地址: http://www.djcxy.com/p/84984.html

上一篇: 如何计算一个圆圈接触哪个方格?

下一篇: 蟒蛇圈周围的多边形区域,周长和边长