Cos function

1
2
3
float angle;
float aimDistance = 100;
AimPositionX = cosf(angle) * aimDistance


My angle vary from 1 to 89

Why does cosf(angle) or any cos function sometimes gives me negative number example (from -1 to 1 )but when i calculate it on a calculator... it never gives me a negative value

Thank you
In C++ cos (and other trigonometric functions) accept angles in radians. 1 radian is 180/pi degrees.
it still gives a nagative number when

AimPositionX = cosf(angle * M_PI / 180) * aimDistance;

What i really want to do is that:
i have an angle that vary from 1 to 89
my hypot is 100

and i just want to work out the adjacent length
And it should give me a positive number of 0 to 100
It certainly should not be negative. Do this:
std::cout << "cos(theta) = " << cosf(angle * M_PI / 180) << ", where theta = " << angle << " deg, = " << angle * M_PI / 180 << " rad\n";
When angle is 45, this should write:
cos(theta) = 0.7, where theta = 45 deg, = 0.78 rad
See what you get.
Topic archived. No new replies allowed.