Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS : Inverse Cosine

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
like image 698
Burf2000 Avatar asked Dec 01 '22 16:12

Burf2000


1 Answers

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.

like image 136
Lutz Lehmann Avatar answered Dec 04 '22 13:12

Lutz Lehmann