Problem with trig functions
It's a pretty simple conversion from three numbers to two angles. tempx,tempy,tempx and magnitude all show up properly but phi and theta both give outputs of zero. I've tried changing them to floats and type casting them as ints but I can't seem to figure it out. Relevant snippets of my code are posted below
Code:
float tempx, tempy, tempz, magnitude;
int phi, theta;
tempx=x/sqrt(x*x+y*y+z*z);
tempy=y/sqrt(x*x+y*y+z*z);
tempz=z/sqrt(x*x+y*y+z*z);
magnitude=sqrt(tempx*tempx + tempy*tempy + tempz*tempz);
phi=atan2(tempy,tempz);
theta=atan(-tempx/sqrt((tempy*tempy)+(tempx*tempx)));
if(phi>359)
phi=359;
if(phi<0)
phi=0;
if(theta>120)
theta=120;
if(theta<0)
theta=0;
UARTprintf("phi=%3d\t",phi);
UARTprintf("theta=%3d\n",(int)(theta*1000));
//panning
fPulseWidth3=(phi+360.0)/360;
//tilting
fPulseWidth2=(206.4-theta)/96;
UARTprintf("fPulseWidth3=%d\tfPulseWidth2=%d\n",fPulseWidth3,(int)(fPulseWidth2*1000));
Thanks for your help