我如何使用atan2
来确定线段结束的坐标,知道它开始的坐标 ( x, y
)、线段的角度和线段的长度?
你能告诉我一个解决方案,它不必只用atan2 ...
您有一个直角三角形,您可以假设点 A 在 (x,y) 处,使用一些图表更容易解释:
现在我们已经知道 c 的值是多少,因为这是段的长度,我们想知道 a 和 b 的值,因为最后一点在(x+b, y+a)
从三角学我们知道角度和边的比率之间的关系是什么
sin(theta) = opposite/hypotenuse
和cos(theta) = adjacent/hypotenuse
代入我们知道的值:
sin(theta) = opposite/c
c = opposite * sin(theta)
和
cos(theta) = adjacent/b
b = adjacent * cos(theta)
我们知道终点是(x+b, y+a)
给定我们找到的边的值(x+adjacent * cos(theta), y+opposite * sin(theta))