java如何计算两个向量之间的角度?
我们试图得到v和u之间的cos值,但我们得到的结果远远大于1或小于0
其中:
vx = in.nextInt(); // x speed of your pod
vy = in.nextInt(); // y speed of your pod
int ux = nextCheckPointIdX - x;
int uy = nextCheckPointIdY - y;
以下是公式:
double cos = (vx*ux + vy*uy) / ( Math.sqrt(Math.pow(vx, 2) + Math.pow(vy, 2)) + Math.sqrt(Math.pow(ux, 2) + Math.pow(uy, 2)) );
你发现前一行有错误吗
# 1 楼答案
分母出了问题