这是我的代码:
# point of intersection between opposite and hypotenuse
x,y = pygame.mouse.get_pos()
# using formula for length of line
lenline1 = (x-x)**2 + (300-y)**2
lenline2 = (x-700)**2 + (y-300)**2
opposite = math.sqrt(lenline1)
adjacent = math.sqrt(lenline2)
# Converting length of lines to angle
PQ = opposite/adjacent
k = math.sin(PQ)
j = math.asin(k)
print(j)
我没有得到我预期的结果,尽管经过一番尝试后我已经接近了,但它不太正确。有人可以告诉我我做错了什么吗?我有两行: 相对且相邻 我希望使用 sin 的倒数得到角度。我究竟做错了什么。我只是一个初学者,所以不要提供太详细的信息。我无法想象这很难做到。
谢谢。
最佳答案
要查找两条线之间的角度,请使用以下关系:
cos(angle) = (l1 dot l2) / (|l1| |l2|)
也就是说,
dotproduct = l1x * l2x + l1y * l2y
lenproduct = |l1| * |l2|
angle = acos(dotproduct / lenproduct)
其中 l1x、l1y 是线 l1 的 x、y 分量。
关于python - 在 python 中使用 Sin-1 或反 sin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12435856/