0
votes

I have equation to find angles of triangle, after the calculation the i get to convert the end results to inverse of Cos function to obtain the angle.I can get the results on a scientific calculator when i input the values, all the steps have same values until the inverse cos function is called. Here are my values. I use the cos formula to calculate the angles of triangle.

calculate(60,100,80) 

calculateAngle( a,b,c){
    var cosC = (this.getSquare(a)+this.getSquare(b)-this.getSquare(c))/(2*a*b)
    console.log(a,b,c,cosC,Math.acos(this.Todegrees(cosC)))
    return Math.acos(this.Todegrees(cosC))
}

getSquare(num){
    return num*num
}

Todegrees(degrees){
    var pi = Math.PI;
    return degrees * (180/pi);
}

The cosC is 0.6 and the the angle result should be 53 degrees. But the angle returned from Math.acos seems not correct.Is my degree to radians function wrong?

1

1 Answers

1
votes

You are applying the conversion to degrees on the wrong side. acos takes a ratio of side lengths or areas and returns an angle in radians. This result you then convert into degrees

return toDegrees(Math.acos(cosC));