我有一个机器人,前面和后面分别安装了红色和绿色的发光二极管。我想计算机器人的头部方向,绿色-红色的矢量指向哪个方向。在
我如何编码,使下面图像中标记为1和2的点具有相同的角度,即逆时针45度,而点3应为225度。在
我使用了以下脚本,但它给出了错误的结果:
def headDirectionAngle(redLEDCoords, greenLEDCoords, referenceVector):
greenRedLEDVector = np.array(greenLEDCoords) - np.array(redLEDCoords)
angle = np.math.atan2(np.linalg.det([referenceVector,greenRedLEDVector]),np.dot(referenceVector,greenRedLEDVector))
return np.degrees(angle)
referenceVector = np.array([0,240])
我该怎么做?谢谢你的帮助。在
回到基础,没有
numpy
。在^{} 已经给出了一个逆时针的角度,但在-180和180之间。您可以添加360并计算模360,以获得介于0和360之间的角度:
x
应该是绿色和红色LED之间的X坐标差。y
也是如此。在相关问题 更多 >
编程相关推荐