【问题标题】:Calculating area of a segment in a circle计算圆中线段的面积
【发布时间】:2013-09-14 02:10:32
【问题描述】:

您将获得直径,以及段或弦的长度。我的问题的直径是 12,弦是 10。你必须找到阴影段的高度,然后打印该区域。原来的公式是A=2/3ch + h^3/2c。我的同学在该地区得到了 18,但当我使用我的代码时,我得到了 41。

这是我能找到的最接近的图片表示。但是从ϴs. 之间有一条虚线

from math import sqrt

diamStr=input("Enter the length of the diameter:   ")

diameter=int(diamStr)

chordStr = input( " Enter the chord length:          ")
chord = int(chordStr)


radius = (diameter/2)

s = sqrt (diameter**2+chord**2)

h = (s/2-radius)

i= (2/3*chord*h)

j=(h**3/2*chord)

area = (i+j)

print (area)

【问题讨论】:

  • 未在问题中找到任何问号。
  • @SargeBorsch 这是“没找到”。 (SCNR)
  • @glglgl 谢谢。有时我的英语有问题。
  • @To_the_oop 你想使用什么样的方程?如果您指出一些网络资源表明该等式是计算分段面积的有效方法,也许我可以将我的解决方案转换为那个难以理解的等式......

标签: python python-3.x


【解决方案1】:

不幸的是,您的公式有问题,但如果用一些初等数学来研究问题,您可能会注意到角度 ϴ 可以使用 cosine rule 找到,因为我们知道 3 个长度 (两个半径和弦长)

在 Python 中是:

theta = math.acos((radius**2 + radius**2 - chord**2)/(2*radius**2))

由于变量theta 已经是弧度,我们可以使用这个公式来计算线段的面积:

在 python 中是area = 1/2 * (theta - math.sin(theta)) * radius**2

因此,在合并所有这些之后,我们提出了一个优雅的解决方案:

import math

diamStr=input("Enter the length of the diameter:   ")
diameter=int(diamStr)

chordStr = input( " Enter the chord length:          ")
chord = int(chordStr)

radius = (diameter/2)
theta = math.acos((radius**2 + radius**2 - chord**2)/(2*radius**2))

area = 1/2 * (theta - math.sin(theta)) * radius**2

#print(round((area),2))
print(area)

如果您输入直径为 12 厘米,弦长为 10,您将得到 18.880864248381847,但您可以通过 round() 函数将其四舍五入到您想要的任意小数位。

例如:print(round((area),2)) 打印 18.88

【讨论】:

  • 你可以简化为theta = math.acos(1 - .5 * chord**2 / radius**2)
  • 正弦规则是我认为最好的 theta = 2 * math.asin(chord/(2*radius)) 虽然需要一些时间来吸收它
猜你喜欢
  • 1970-01-01
  • 2011-06-24
  • 2021-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-17
  • 1970-01-01
相关资源
最近更新 更多