Вопрос

I'm trying to use trigonometry to find distances and a-like..

Currently though, I believe my formula to be correct but I get an incorrect degrees when using sin,cos,tan with a particular degree

double hypotenuse = [distanceOnTimeScale.text doubleValue];

double fita = 90 - probeAngle;

double sinFita = sin(fita);

double hypCheck = (opposite / sinFita);

double secondLeg = hypotenuse - hypCheck;

double adjacent = (opposite / tan(fita));

NSLog(@"Opposite: %.1f", opposite);
NSLog(@"Fita: %.1f", fita);
NSLog(@"Hypotenuse: %.1f", hypotenuse);
NSLog(@"Hyp Check: %.1f", hypCheck);
NSLog(@"FITA: %f", sinFita);

outputs

2014-04-18 16:35:51.988 ---[7316:60b] Opposite: 10.0
2014-04-18 16:35:51.991 ---[7316:60b] Fita: 45.0
2014-04-18 16:35:51.992 ---[7316:60b] Hypotenuse: 0.0
2014-04-18 16:35:51.993 ---[7316:60b] Hyp Check: 12.4
2014-04-18 16:35:51.994 ---[7316:60b] FITA: 0.806075

As you can see Fita is 45º

so, sinFita should equal 0.707106781186547 and it does not, why am I getting this issue?

Это было полезно?

Решение 2

you need to do

double sinFita = sin(fita * M_PI / 180);

to convert degrees to radians. Which is the conversion factor from degrees to radians.

Другие советы

The C math functions (e.g. sin) expect their arguments to be in radians, not degrees.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top