Reputation: 1
What's wrong with this degree calculation?
I've chosen 2 vectors, which should have a degree of 90°.
I tried it with cos, cos^-1 and without cos calcualtion. but the output of my code is:
0 (without cos calculation)
1 (cosinus)
1.5707963267949 (cosinus^-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))
Upvotes: 0
Views: 249
Reputation: 25873
Math functions work with radians, so your comparisons and operations must be in radians as well, not degrees.
Upvotes: 1
Reputation: 262684
1.5707963267949 (cosinus^-1(acos))
That looks like 90 degrees ( pi/2)
Upvotes: 1