python怎么用sin,在Python中使用Sin-1或反正弦

Here is my code:

# 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.

Thanks.

解决方案

To find the angle between two lines, use the following relation:

cos(angle) = (l1 dot l2) / (|l1| |l2|)

That is,

dotproduct = l1x * l2x + l1y * l2y

lenproduct = |l1| * |l2|

angle = acos(dotproduct / lenproduct)

where l1x, l1y are the x,y components of the line l1.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值