点之间的编程角度 [英] Programming angles between points

查看:102
本文介绍了点之间的编程角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对用户触摸屏幕的小功能进行编程,例如2个箭头指向触摸位置.

I would like to program a small feature where the user touches the screen, and e.g. 2 arrows point towards the touch location.

如果在中间,底部附近有一个触摸位置,那么如何计算它们之间的角度或与之形成的方向?

If there is a touch location in the middle, near the bottom, how does one calculate the angle between these or the direction to it?

我想获得箭头的源之间的角度,可以说它是一个圆,并且我希望该角度从圆的边缘指向触摸位置.我想知道箭头应该从圆圈开始的哪个位置,以便与触摸位置具有正确的角度.

I want to get the angle between the source of the arrow, lets say it is a circle, and I want the angle to point from the edge of the circle to the touch location. I want to be able to know where in the circle the arrow should start from, in order to have the correct angle to the touch location.

推荐答案

要找到90度角与您的点之间的夹角,您只需使用一些基本的三角函数即可.

To find the angle between a 90 deg angle and your point you can just use some basic trigonometry.

如果您想象在(触摸x,点y)的第三个点B,您将得到一个直角三角形.然后找到您的角度很简单,因为tan(angle)=对边/相邻边,或(xa-xb)/(yb-yt).所以angle = tan^-1((xa - xb)/(yb - yt)).

If you imagine a third point B at (x of touch, y of point), you'll end up with a right triangle. Then finding your angle is simple since tan(angle) = opposite side/adjacent side, or (xa - xb)/(yb - yt). So angle = tan^-1((xa - xb)/(yb - yt)).

这篇关于点之间的编程角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆