我对这个有点困惑。
我有一个物体,我知道它在 x 轴和 y 轴上的速度。我的问题是如何确定它移动的 Angular 。
function Object(){
this.velocity = {x: 5, y: 1};
}
基本上我知道矢量的方向是 x_projectioncos(deg) + y_projectionsin(deg),但我不知道如何获得这些投影,因为我只有速度,因为我说我真的很困惑。
#编辑:
除了已接受的答案之外,以下是我为获得完整的 360 度光谱所做的事情
var addDeg = 0;
if(obj.velocity.x<0)
addDeg = obj.velocity.y>=0 ? 180 : 270;
else if(obj.velocity.y<=0) addDeg = 360;
deg = Math.abs(Math.abs(Math.atan(obj.velocity.y/obj.velocity.x)*180/Math.PI)-addDeg)
最佳答案
I don't know how to get those projections since I only have the velocity
实际上,您似乎缺少的是您已经有了预测。这就是 x 和 y。
x 是速度 * cos( Angular )
y 是速度 * sin( Angular )
所以 y/x = sin( Angular )/cos( Angular ),即 tan( Angular ),所以 Angular =arctan(y/x)。
这是从x轴开始逆时针旋转的 Angular (x指向右,y指向上)。
关于javascript - 根据速度确定运动矢量的方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22421054/