python - 用python计算圆周围的多边形面积、周长和边长

标签 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

最佳答案

您只需在现有公式中使用边心因数 (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/

相关文章:

c++ - 使用边缘检测计算三角几何中的顶点法线

javascript - 按每个数组中包含的元素对数组数组进行排序

algorithm - 没有浮点计算的画圆

python - python-attrs 中带有额外参数的自定义验证器

python - 知道如何使用 scrapy 访问此网址吗?

algorithm - 有没有更好的方法来使用图像 0.18 crate 实现中点圆算法?

language-agnostic - 有效地找到直线数组的交点

python - 从 Numpy 数组中选择每列满足某些条件的所有行

python - 以编程方式添加和删除 tkinter python 标签会导致 IndexError : list index out of range

python - 阈值numpy数组,查找窗口