Search code examples
pythontrigonometry

Python (pygame) Sin, Cos and Tan


I noticed there was a sin, cos and tan function in Python.

So, I thought I would use these to make a way of aiming in my game, unfortunately, the word description of sin,cos,tan,asin,acos and atan are very confusing.

I know how to do all the sin, cos and tan rules from school, I just need to apply them to the code. So, here's what I need to do, I just need to know which one I must use:

I have

  1. The Angle
  2. The Hypotenuse
    (I'm just keeping that the value of how far I want the object to travel before I blit it again)

From the angle, I want to work out either/both the opposite and adjacent.
The hypotenuse is going to be sin/asin and cos/acos. Which one? I don't know.

How to I input my numbers? Do I just do aim = cos(angle,hyp) or do I have to apply some other calculations?


Solution

  • The formulae are:

    adjacent = hypothenuse * math.cos(angle)
    opposite = hypothenuse * math.sin(angle)
    

    where angle is in radians.