這個度數計算有什麼問題?2個向量之間的度數?
我已選擇2個矢量,它們的本色應爲90°。
我試了cos,cos^-1,沒有cos calcualtion。但我的代碼的輸出爲:
0(無COS計算)
1(餘弦)
1.5707963267949(餘弦^ -1(ACOS))
local square = math.sqrt;
local weaponVector, hitVector = , {x = 0, y = 0, z = 1,}, {x = 0, y = 1, z = 0,};
local xW, yW, zW = weaponVector.x, weaponVector.y, weaponVector.z;
local xH, yH, zH = hitVector.x, hitVector.y, hitVector.z;
local angleBetweenWeaponAndHitDirection = math.acos(math.abs(xW*xH+yW*yH+zW*zH)
/(square(xW*xW+yW*yW+zW*zW) * square(xH*xH+yH*yH+zH*zH)));
if (angleBetweenWeaponAndHitDirection>180) then
angleBetweenWeaponAndHitDirection = 360-angleBetweenWeaponAndHitDirection;
end
print(angleBetweenWeaponAndHitDirection)
print(math.cos(angleBetweenWeaponAndHitDirection))
print(math.acos(angleBetweenWeaponAndHitDirection))