Sine to radians Objective-C

試著忘記壹切 提交于 2019-12-13 08:56:41

问题


This part of an app that I am working on, I have the following equation in objective C. All variables are floats. r is a sine of an angle and I would like to convert r to radians when diplayed in the text field.

r = ns/ni
r = sinf(r);
rr = asinf(r);

textfieldRi.text = [NSString stringwithFormat:@"%.02f", rr];

I am not getting correct results. Any suggestions please?


回答1:


I'm not entirely certain what you think you're gaining by executing a sine followed by an inverse sine, except possibly to ensure the range of r is reduced to it's smallest range, in which case asin(sin(r)) should work fine, assuming r is already in radians.

If you want to convert r to radians, I have to assume it's currently in degrees, in which case you just need to do something like:

radians = degrees * 3.141592653589 / 180.0; // or M_PI in math.h.



回答2:


Objective-c automatically uses radians instead of degrees, however to convert degrees to radians divide by 180 then multiply by PI.



来源:https://stackoverflow.com/questions/10005290/sine-to-radians-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!