Sorry for the beautiful dumb question I'm slowly learning mathematics from scratch.
I want to calculate the angle of the triangle through javascript.
I calculate the length of sides,
ab = math.abs (b.x - c.x); Ac = math BAS (BI-CI); A = Math.Sqrt ((AB * AB) + (AC * AC)); BB = Math Box (Ax - C. X); BC = Math Abbas (AI-Si); B = Math.Sqrt ((BB * BB) + (BC * BC)); CB = Math Box (Ax-BX); Cc = math Abbas (AI-BI); C = Math.Sqrt (CB * CB) + (CC * CC)); And then I go to this point:
angleB = Math.cos (((C * C) + (A * A) - ( B * B)) / (2 * C * A)); However, I get a completely wrong number Why is it like this?
Your code uses Math.cos when it's Math should use .acos . Starting with it, we get the correct formula:
b * b = a * a + c * c - 2 * a * c * cos (angel) B * B - A * A - C * C = 2 * A * C * Cos (angel) 2 * A * C * cos (angel) = A * A + C * C - B * B cos (angleB) = ( A * c + c * c - b * b) / (2 * a * c) angle b = aoo ((a * c + c * c - b * b) / (2 * a * c))
No comments:
Post a Comment