making atanf2 with atanf

Oct 27, 2008 at 6:04pm
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
Oct 27, 2008 at 6:13pm
Trigonometric function take/give radian values, try to fix it in this way:
theta = atanf(y/x)*180/3.14;
Oct 28, 2008 at 5:26pm
nah that didnt worked wrong output numbers again :(
Last edited on Oct 28, 2008 at 5:27pm
Oct 28, 2008 at 6:16pm
Try outputting some known values and see what atanf(y/x)*180/pi gives...like 3/4 should give 60 if I remembering correctly.
Oct 28, 2008 at 8:34pm
Lol it worked perfectly for me =S....
Oct 28, 2008 at 9:33pm
minaadel1994 could you post full code of yours, so i can test it if it really works?
Oct 28, 2008 at 10:10pm
I think would be better if you post your full code to see what is wrong with it
Oct 29, 2008 at 7:19pm
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 Oct 29, 2008 at 7:21pm
Oct 29, 2008 at 8:21pm
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;

}
Oct 30, 2008 at 6:01pm
cool it works now, you should said that before :)
Last edited on Oct 30, 2008 at 6:02pm
Oct 30, 2008 at 7:06pm
*cough*Ithoughtitwasobvious*cough* It's not like the function is suddenly changed between uses...>.>
Topic archived. No new replies allowed.