Credit-help.pro

Credits

Finances

Banks

# What are derivatives in math

The tangent formula is this:

Refer to this drawing:

Where a is the adjacent side, o is the opposite side and theta is the angle. Similarly, sine and cosine are sin(ang)=o/h and cos(ang)=a/h where h is the long side: http://www.mathwords.com/s/sohcahtoa.htm

Meanwhile atan (short for arc-tangent. also known as the inverse tangent ) is the reverse of tan. like so:

Thus, if you know the values of both the opposite and adjacent sides (for example, by subtracting the object's coordinates from the mouse coordinates) you can get the value of the angle with atan .

In game development though, it can happen fairly often that the adjacent side is equal to 0 (e.g. the x coordinate of a vector being 0). Remembering that tan(angle) = opposite/adjacent the potential for a disastrous divide-by-zero error should be clear. So a

lot of libraries offer a function called atan2. which lets you specify both the x and y parameters, to avoid the division by zero for you and give an angle in the right quadrant.