I am trying to write an algorithm in Swift to work out the angles of a triangle. For ref check https://www.mathsisfun.com/algebra/trig-solving-sss-triangles.html
I am trying to fine the cos−1 command which I believe is inverse cosine
I have tried acos and acosh, both do not produce the correct value based on this site http://www.rapidtables.com/calc/math/Arccos_Calculator.htm
Does anyone know what the cos-1 function is on iOS
//https://www.mathsisfun.com/algebra/trig-solving-sss-triangles.html
totalDistance = 8
arm1 = 6
arm2 = 7
var angleA = (pow(arm1, 2) + pow(arm2, 2) - pow(totalDistance,2)) / (2 * arm1 * arm2)
print(angleA) // I get 0.25 : correct
print( acos(angleA)) // I get 1.31811607165282 : should be 75.5
print( acosh(angleA)) // I get nan
The inverse is acos
for arccos. The result is in radians, you have to translate into degrees to get to your wanted result.
print( acos(angleA)*180/Pi)
If you scroll down in the arccos calculator, you will also find the radians value represented.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With