【发布时间】:2014-05-15 13:06:16
【问题描述】:
我有计算圆上内接多边形的面积、周长和边的函数,但我想找到类似的通用方法来计算围绕圆绘制的多边形的相同属性。
# 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 可能与 apothem 有关,就像这张照片一样。问题是,我只知道圆的半径:
【问题讨论】:
-
对我来说听起来更像是一个纯数学问题,没有任何真正的 CS/编程联系。
-
是的,半径与 apothem 的关系是外部多边形与内部多边形相关的因素。所以你只需要计算
factor = radius/apothem,然后将面积乘以factor²,将长度乘以factor。 -
还有
apothem = radius * cos(pi / n),所以factor = 1/cos(pi / n)。