我正在尝试根据此处的示例对函数建模,但是使用相同的参数却得到了不同的结果。
def getTwoSidesOfASATriangle(a1, a2, s):
'''
Get the length of two sides of a triangle, given two angles, and the length of the side in-between.
args:
a1 (float) = Angle in degrees.
a2 (float) = Angle in degrees.
s (float) = The distance of the side between the two given angles.
returns:
(tuple)
'''
from math import sin
a3 = 180 - a1 - a2
result = (
(s/sin(a3)) * sin(a1),
(s/sin(a3)) * sin(a2)
)
return result
d1, d2 = getTwoSidesOfASATriangle(76, 34, 9)
print (d1, d2)
感谢@Stef为我指出正确的方向。这是工作示例,以防将来对某人有所帮助。
def getTwoSidesOfASATriangle(a1, a2, s, unit='degrees'):
'''
Get the length of two sides of a triangle, given two angles, and the length of the side in-between.
args:
a1 (float) = Angle in radians or degrees. (unit flag must be set if value given in radians)
a2 (float) = Angle in radians or degrees. (unit flag must be set if value given in radians)
s (float) = The distance of the side between the two given angles.
unit (str) = Specify whether the angle values are given in degrees or radians. (valid: 'radians', 'degrees')(default: degrees)
returns:
(tuple)
'''
from math import sin, radians
if unit is 'degrees':
a1, a2 = radians(a1), radians(a2)
a3 = 3.14159 - a1 - a2
result = (
(s/sin(a3)) * sin(a1),
(s/sin(a3)) * sin(a2)
)
return result