• Log in or sign up for an account here: https://www.sythe.org/login

Help with atan2f function!

Cherry65

Forum Addict
Joined
Jan 31, 2007
Sythe Gold
0
Messages
447
Age
34
Location
Argentina
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);
 
Le Monkey
Potamus
Prove it!
Sythe Awards 2011 Winner
Tier 1 Prizebox
Tortoise Penis
Trole
UWotM8?
Wait, do you not have an Archer rank?
It gives the result in radians.

result = result/PI * 180
or something like that, however you convert between the two.
 
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?
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
 
Runescape Gamblingrunescape gambling
Back
Top