As you can see in my screenshot i try to calculate the angle between the coordinates AB and BC, in this case the angle is obviously 90°. But how can i determine this angle with javascript code?
I found this thread and tried the accepted solution, but i always get 1.57
instead of 90 like i expected. I rewrote the original function because i did not understood how to pass my parameters to it.
Please excuse my bad paint and math skills.
function find_angle(Ax,Ay,Bx,By,Cx,Cy)
{
var AB = Math.sqrt(Math.pow(Bx-Ax,2) + Math.pow(By-Ay,2));
var BC = Math.sqrt(Math.pow(Bx-Cx,2) + Math.pow(By-Cy,2));
var AC = Math.sqrt(Math.pow(Cx-Ax,2) + Math.pow(Cy-Ay,2));
return Math.acos((BC*BC+AB*AB-AC*AC) / (2*BC*AB));
}
var angle = find_angle
(
4 , //Ax
3 , //Ay
4 , //Bx
2 , //By
0 , //Cx
2 //Cy
)
alert ( angle );