蟒蛇圈周围的多边形区域,周长和边长

我有函数来计算圆上刻的多边形的面积,周长和边,但我想找出类似的一般方法来计算围绕圆周绘制的多边形的相同属性。

落款

# 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

答案可能与apothem有关,就像这张照片一样。 问题是,我只知道圆的半径:


你只需要使用现有公式中的apothem( apothem = radius * cos(pi/n) )因子(我没有检查):

# 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

我改变了函数的顺序,将perimeter放在side (反之亦然),以避免在计算polygon_side长度时乘法,然后再乘以n

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

上一篇: Polygon area, perimeter and side length around the circle with python

下一篇: Find the midpoint of overlap between circle and rectangle