Calculating triangle angle

Discussion in 'iOS Programming' started by TodVader, Aug 15, 2009.

  1. TodVader macrumors 6502a

    TodVader

    Joined:
    Sep 27, 2005
    Location:
    Quebec, Canada
    #1
    Hi. I'm not too sure about the technical words since I speak french but I have a rectangle triangle (with a 90degree angle).

    I know both sides (x,y) so to get the hypothenuse, I did this:

    float hyp = sqrt((difX * difX) + (difY * difY));

    Now, to get the angle I want, I did this:

    float rocketAngle = acos(difX/hyp); // difX/hyp should give me the cos of my angle.

    I don't understand why it doesn't work. I apply a rotation to my missile with the angle of rocketAngle and it stays straight. My rotation code works if I test it with a static number.

    This is done with OpenGL btw.
     
  2. -aggie- macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #2
    Not sure how you're using the rocket angle, but it's probably a degrees to radians issue. acos gives the angle in radians.
     
  3. TodVader thread starter macrumors 6502a

    TodVader

    Joined:
    Sep 27, 2005
    Location:
    Quebec, Canada
    #3
    Nice! Thankyou, that is probably the problem right there. I will go try this.
     
  4. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    That's called a right triangle.

    The c library math functions work with radians, not degrees.
     
  5. TodVader thread starter macrumors 6502a

    TodVader

    Joined:
    Sep 27, 2005
    Location:
    Quebec, Canada
    #5
    Thankyou for the clarification. In french its a "Triangle rectangle"

    Btw, this worked perfectly, I can now move on to different things.

    Thanks for the help!

    I just did (Radian*180)/PI
     
  6. -aggie- macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #6
    Glad to help. I thought of writing my response en francais, but then no one else would know what I wrote. :)

    Au revoir!
     

Share This Page