Help with atan2f function!

Discussion in 'Programming General' started by Cherry65, Nov 21, 2008.

Help with atan2f function!
  1. Unread #1 - Nov 21, 2008 at 10:18 AM
  2. Cherry65
    Joined:
    Jan 31, 2007
    Posts:
    447
    Referrals:
    0
    Sythe Gold:
    0

    Cherry65 Forum Addict
    Banned

    Help with atan2f function!

    Im doing some exercises from a book, and in one of them i have to rewrite the function atanf2. First, i wanted to explore a bit about this function, and while doing this i noticed that the results given by this function differed from the ones given in the book. For example, the book says that atan2f(4,2) = 63.46(degrees) and when i do this:
    Code:
    #include <iostream>
    #include <cmath>
    using namespace std;
    
    int main()
    {
    	cout << atan2f(4,2) << endl;
    	system("PAUSE");
    }
    
    the result is 1.1 pi, that is 198 degrees. When i check this on a sheet of paper i realise that the result given by the book is the correct one. Whats wrong with this?

    Maybe i misunderstood the excercise. This is the exercise:
    Code:
    Using atanf, write a function with the following prototype:
    
    float MyArcTangent(float y, float x);
    
    This function should examine the signs of coordinates of the point (x, y) and return the correct angle based on what quadrant the point lies in. Test your function with the following points: (2,4), (-1,5), (-6,-4), (4, -6). You sould get the following results:
    
    MyArcTangent (4, 2) = 63.4671
    MyArcTangent (5, -1) = 101.27
    MyArcTangent (-4, -6) = 213.707
    MyArcTangent (-6, 4) = -56.3385
    Press any key to continue
    
    Now that you have written the function yourself, you should know that the C++ standard math library already includes a function that does what your function does. Its prototype is:
    
    float atanf2(float y, float x);
    
     
  3. Unread #2 - Nov 21, 2008 at 3:30 PM
  4. Govind
    Joined:
    Apr 22, 2005
    Posts:
    7,825
    Referrals:
    13
    Sythe Gold:
    23
    Prove it! Trole Tier 1 Prizebox Tortoise Penis Le Monkey UWotM8? Wait, do you not have an Archer rank? Potamus

    Govind The One Musketeer
    Mudkips Highly Respected Retired Administrator

    Help with atan2f function!

    It gives the result in radians.

    result = result/PI * 180
    or something like that, however you convert between the two.
     
  5. Unread #3 - Nov 21, 2008 at 7:21 PM
  6. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    Help with atan2f function!

    SMR is right, you are using the incorrect conversion. There is nothing wrong with the function or your understanding of it.

    Radians * 180 / PI = Degrees

    1.1 Radians * 180 / PI = 63.03 Degrees
     
< getline fuction | Help >

Users viewing this thread
1 guest


 
 
Adblock breaks this site