making atanf2 with atanf

hi,

im trying to make atanf2 function (float MyArcTangent(float y, float x);) with atanf function (..).

But im having problem with the autput values, i cant seem to find out whats wrong

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <cmath>
using namespace std;

float theta;

void MyArcTangent(float y, float x);

int main()
{
	MyArcTangent( 4, 2 );
	MyArcTangent( 5, -1 );
	MyArcTangent( -4, -6 );
	MyArcTangent( -6, 4 );
}

void MyArcTangent(float y, float x)
{
	
	if( x > 0 )
	{
		theta = atanf(y/x);              
	}
	else
		theta = atanf(y/x) + 180.0f;   
	
	cout << "MyArcTangent( " << y << ", " << x << ") = " << theta << endl;

}



i should get these values:

MyArcTangent( 4, 2) = 63.4671
MyArcTangent( 5, -1) = 101.27
MyArcTangent(-4, -6) = 213.707
MyArcTangent(-6, 4) = -56.3385

but instead, i get 1.10715, 178.672,...

ty for all the help
Trigonometric function take/give radian values, try to fix it in this way:
theta = atanf(y/x)*180/3.14;
nah that didnt worked wrong output numbers again :(
Last edited on
Try outputting some known values and see what atanf(y/x)*180/pi gives...like 3/4 should give 60 if I remembering correctly.
Lol it worked perfectly for me =S....
minaadel1994 could you post full code of yours, so i can test it if it really works?
I think would be better if you post your full code to see what is wrong with it
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <cmath>
using namespace std;

float theta;

void MyArcTangent(float y, float x);

int main()
{
	MyArcTangent( 3, 4 );
	MyArcTangent( 5, -1 );
	MyArcTangent( -4, -6 );
	MyArcTangent( -6, 4 );
}

void MyArcTangent(float y, float x)
{
	
	if( x > 0 )
	{
		theta = atanf(y/x);              
	}
	else
		theta = atanf(y/x)*180/3.14;  
	
	cout << "MyArcTangent( " << y << ", " << x << ") = " << theta << endl;

}


edited the line you typed...
Last edited on
n*180/3.14 converts 'n' from randians to degrees.
1
2
3
4
5
6
7
8
9
10
11
12
13
void MyArcTangent(float y, float x)
{
	
	if( x > 0 )
	{
		theta = atanf(y/x)*180/3.14;              
	}
	else
		theta = atanf(y/x)*180/3.14 + 180;  
	
	cout << "MyArcTangent( " << y << ", " << x << ") = " << theta << endl;

}
cool it works now, you should said that before :)
Last edited on
*cough*Ithoughtitwasobvious*cough* It's not like the function is suddenly changed between uses...>.>
Topic archived. No new replies allowed.