计算ci中线段的面积

2024-10-01 11:20:48 发布

您现在位置:Python中文网/ 问答频道 /正文

您将得到截面直径和线段或弦的长度。我问题的直径是12,和弦是10。您必须找到阴影部分的高度,然后打印该区域。原始公式是A=2/3ch + h^3/2c。我的同学在这个区域得到了18分,但是当我使用我的代码时,我得到了41分。在

这是我能找到的最接近的图片。但是有一条虚线从ϴs.Image retrieved from wolfram.com

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)

Tags: the区域inputareasqrtlengthintenter
1条回答
网友
1楼 · 发布于 2024-10-01 11:20:48

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

Obtained from mathsisfun.com

在Python中是:

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

由于变量theta已经以弧度表示,我们可以使用以下公式计算线段的面积:

enter image description here

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

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

^{pr2}$

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

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

相关问题 更多 >