问题
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