1. ## Trig Ratios

Hi,

I had been calculating movement on a 2-d axis a very complicated way that required lots of code, but I recently have come to understand how you can use cos and sin to calculate the movement of X and Y based of a heading (out of 360 deg.)

I'm having trouble implementing it though. The way I was attempting to do it was like this:
Code:
```xShots[count] += sin(shotHeading[count])*0.3f;
Then I realized that the ratios have a pattern (or something like it) every 90 deg. I looked at a nehe tutorial that used this method and it was like this:
Code:
```xpos -= (float)sin(heading*piover180) * 0.05f;
Can someone attempt to show me how to do this, or should I just go read a math book?

David

2. The two methods aren't really different. The main point is that sin() and cos() take the angle in radians; the piover180 is the conversion factor.

3. So the pie over 180 converts it to the radians? Is it required that I convert it to a radian?

Edit: Well adding in the pieover180 worked, but I don't know why and that really bugs me.

Edit again: Never mind, I just didn't read what you wrote well. pi over 180 is the conversion to degrees.

Thanks!

4. pi / 180 is the conversion to radians. When you multiply by it, you essentially multiply by 1. pi radians is equal to 180 degrees. Go read up about what Radians are.
Also, read this article as it contains a skill that is invaluable, and will aid you in converting between units. (radians to degrees, feet to miles, or more exotic units.) Has to be one of the greatest things a Chem teacher I had taught me.

It's "pi", not food.

5. Thanks for the article. That was a typo eariler, I had looked radians up.

6. Actually you are still going to run into problems. What is the 0.05f for? Is that your speed?

Code:
```#define PI 3.14159f
#define DEGTORAD(angle)       (float)((float)angle * PI / 180.0f)

Of course I don't recommend doing the conversion in a time critical loop.

7. Well it's not too time critical, but are you saying that I should make the calculation once, then just increment by the number I get each loop? Because the angle isn't going to change in this particular instance.

And yea the 0.05f was speed.

8. Originally Posted by Cactus_Hugger
Also, read this article as it contains a skill that is invaluable, and will aid you in converting between units. (radians to degrees, feet to miles, or more exotic units.) Has to be one of the greatest things a Chem teacher I had taught me.
Dimensional analysis (algebra on units) can even be used to deduce various laws of physics. For instance, the formula for the speed of transverse wave propagation on a string can be derived using dimensional arguments alone, without doing any physical calculations. At least up to various dimensionless constants.

9. Originally Posted by IdioticCreation
Well it's not too time critical, but are you saying that I should make the calculation once, then just increment by the number I get each loop? Because the angle isn't going to change in this particular instance.

And yea the 0.05f was speed.
Yes that's what he's saying, since addition is faster than division and multiplication.

Just remember that +1 radian is not +1 degree...

10. Well I actually was talking about incriminating the X and Y not the angle. Like calculate it to find how much X and and Y should increase each frame (The Slope) then just add them.