向量之间的夹角 atan2(y2,x2) - atan2(y1,x1) 解释

我在使用游戏引擎Love2D Lua时,注意到了HUMPS向量代码内的以下公式(https://github.com/vrld/hump/blob/master/vector.lua):

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

注意:atan2在此处的描述为https://en.wikipedia.org/wiki/Atan2:基本上,它是一种安全的atan函数,可以防止由于零除和其他atan陷阱而导致的错误。

我一直在绘制两个不同向量的图形,并试图弄清楚像这样的公式是如何得出的。对我来说,这个公式的上下文是将图像(image_pos)旋转到鼠标单击的位置(mouse_pos)。

有谁能够以ELI5的方式来解释这个公式是如何推导出来的/它是如何工作的吗?

点赞
用户3768871
用户3768871

从图片中可以看出,这是两个向量之间的角度差异。

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

2018-01-15 14:11:28