圆形周围的多边形区域,周长和边长与python

时间:2014-05-15 13:06:16

标签: python geometry

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

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

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

inner outer circle

1 个答案:

答案 0 :(得分:2)

您只需要在现有公式中使用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再乘以。{/ p>