矢量atan2(y2,x2) - atan2(y1,x1)之间的角度说明

时间:2018-01-15 13:41:53

标签: math vector graphics

因此,在玩游戏框架Love2D lua引擎时,我注意到HUMPS向量代码(https://en.wikipedia.org/wiki/Atan2)中的以下论坛:

return atan2(self.y, self.x) - atan2(other.y, other.x)

注意:此处描述了atan2 {{3}}  :基本上它是一个安全的atan功能,可以防止零除以及其他一些弊端 - 据我所知。

我已经绘制了两个不同矢量的图形,并试图弄清楚某人会如何想出这样的公式。至少对我来说,这个公式的上下文是将图像(image_pos)旋转到鼠标点击的位置(mouse_pos)。

任何人都可以请ELI5如何推导出这个公式/它如何运作?

1 个答案:

答案 0 :(得分:1)

正如你在图片中看到的那样,两个向量之间的角度差异。

enter image description here

atan2(self.y, self.x) == \beta

atan2(other.y, other.x) == \alpha

因此:

atan2(self.y, self.x) - atan2(other.y, other.x) == \theta

相关问题