我给定了三角形的两条腿,在使用毕达哥拉斯计算出第三条腿后,我必须找到三角形的角度才能使用 Turtle 在 Python 中绘制三角形。
我已尝试使用余弦公式求出角度,但没有用。我没有得到想要的结果。
代码:
import math
import turtle
#Legs
a = 70
b = 60
c_pwr = a**2 + b**2
c = math.sqrt(c_pwr)
print("Langste zijde is: ", c)
#Angles
A = math.acos((b**2 + c**2 - a**2) / (2 * b * c)) * 100
B = math.acos((c**2 + a**2 - b**2) / (2 * c * a)) * 100
C = 360 - A - B
print(A, " ", B, " ", C)
turtle.forward(a)
turtle.right(B)
turtle.forward(b)
turtle.right(A)
turtle.forward(c)
input()
我做错了什么以及如何解决?谢谢!
请您参考如下方法:
acos 以弧度返回边,因此您必须将其转换为六十进制度数,为此您必须乘以 180/π。我们也知道内角和是180,所以第三个角是180-A-B。
还有一个问题是绘制必须传递的角度,默认绘制是从右向左前进到,那么必须旋转180-A,前进c,旋转180-B,前进b
a = 70
b = 60
c_pwr = a**2 + b**2
c = math.sqrt(c_pwr)
print("Langste zijde is: ", c)
#Angles
A = math.acos((b**2 + c**2 - a**2) / (2 * b * c))*180/math.pi
B = math.acos((c**2 + a**2 - b**2) / (2 * c * a))*180/math.pi
C = 180 - A - B
print(A, " ", B, " ", C)
turtle.forward(a)
turtle.right(180-B)
turtle.forward(c)
turtle.right(180-A)
turtle.forward(b)
输出:
