我有计算圆上内切多边形的面积、周长和边长的函数,但我想找到类似的通用方法来计算围绕圆绘制的多边形的相同属性。
# 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 = 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
我更改了函数的顺序,将周长
基于一侧
(反之亦然),以避免乘以然后潜水n
计算多边形边长时。
关于python - 用python计算圆周围的多边形面积、周长和边长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23679130/