在Python中使用Sin-1或反正弦 [英] Using Sin-1 or inverse sin in python
本文介绍了在Python中使用Sin-1或反正弦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
# 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)
我没有得到我期望的结果,尽管在弄乱它之后我已经接近了,但并不完全正确.有人可以告诉我我做错了什么.我有两行: 对面和相邻 我希望用罪的逆来获得角度.我究竟做错了什么.我只是一个初学者,所以请不要提供太多详细信息.我无法想象这很难做到.
I'm not getting the results I expected, although after messing around with it I got close but it wasn't quite right. Could someone please tell me what I'm doin wrong. I have two lines: opposite and adjacent And I wish to get the angle using the inverse of sin. What am I doing wrong. I'm only a beginner so don't give too detailed info. I can't imagine this is hard to do.
谢谢.
推荐答案
要找到两条线之间的角度,请使用以下关系:
To find the angle between two lines, use the following relation:
cos(angle) = (l1 dot l2) / (|l1| |l2|)
也就是说,
dotproduct = l1x * l2x + l1y * l2y
lenproduct = |l1| * |l2|
angle = acos(dotproduct / lenproduct)
其中l1x,l1y是线l1的x,y分量.
where l1x, l1y are the x,y components of the line l1.
这篇关于在Python中使用Sin-1或反正弦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文