Trigonometry in Game Development: Sine and Cosine

Math is important part of the game development. If you know math as well then you have a great advantage on development process. Let's start learn about Triginometry. In this post, I will examine sine and cosine functions of Trigonometry. Sine and cosine functions return ratio of side according to the given angle. Our formulas that we will use:

sine and cosine function
I want to generate sine and cosine waves using these functions. So let's visulalize this wave using sinus function formula:

We understood a sinus wave how can be created according to the above. However, We should know a special formula in addition. The correct usage of this formula gives us an effective managment about wave like wavelength, the position of the wave, etc.

y = A * (sin(B * (x - C))) + D

  • A: It represents the wavelength of the wave, also it is known as amplitude.
  • B: It represents the period of the wave. (the defined line that one peak from the anoher peak is a period)
  • x and y is one point's position.
  • C: the horizontal position of the wave.
  • D: the vertical position of the wave
Let's make an example program according these knowledges:
circle.Position = new Vector2f(circle.Position.X + speed, 20 * MathF.Sin((1/10f) * (circle.Position.X - 0)) + 240);

No comments:

Post a Comment