【问题标题】:Polygon area, perimeter and side length around the circle with python用python围绕圆的多边形面积、周长和边长
【发布时间】: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)

标签: python geometry


【解决方案1】:

您只需要在现有公式(我没有检查)中使用 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

我更改了函数的顺序,使perimeterside 为基础(反之亦然),以避免在计算多边形边长时乘以n

【讨论】:

  • 谢谢,这似乎有效,至少对于正方形。我需要仔细检查其他多边形。我还可以使用原始函数来简化面积和周长函数 -> polygon_perimeter(r, n) / cos(pi/n)。
猜你喜欢
  • 1970-01-01
  • 2017-03-18
  • 1970-01-01
  • 2016-01-17
  • 1970-01-01
  • 2023-01-30
  • 2023-01-31
  • 2015-04-23
  • 1970-01-01
相关资源
最近更新 更多