H
harryos
while searching for code to find phase angle from real and imaginary
parts of a complex number ,I came across this snippet .It does some
quadrant correction.
double getPhaseAngle(double real,double imag){
double ang=0.0;
double pi=Math.PI;
if(imag == 0.0 && real == 0.0){ang = 0.0;}
else{ang = Math.atan(imag/real)*180.0/pi;}
if(real < 0.0 && imag == 0.0){ang = 180.0;}
else if(real < 0.0 && imag == -0.0){
ang = -180.0;}
else if(real < 0.0 && imag > 0.0){
ang += 180.0;}
else if(real < 0.0 && imag < 0.0){
ang += -180.0;}
return ang;
}
I could not understand why there is a check for imag == -0.0.
Can imaginary part ever become -0.0?Is that not the same as imag==0.0?
Is there a difference?
If someone can explain the maths in this,it would be a great help.
thanks in advance
harry.
parts of a complex number ,I came across this snippet .It does some
quadrant correction.
double getPhaseAngle(double real,double imag){
double ang=0.0;
double pi=Math.PI;
if(imag == 0.0 && real == 0.0){ang = 0.0;}
else{ang = Math.atan(imag/real)*180.0/pi;}
if(real < 0.0 && imag == 0.0){ang = 180.0;}
else if(real < 0.0 && imag == -0.0){
ang = -180.0;}
else if(real < 0.0 && imag > 0.0){
ang += 180.0;}
else if(real < 0.0 && imag < 0.0){
ang += -180.0;}
return ang;
}
I could not understand why there is a check for imag == -0.0.
Can imaginary part ever become -0.0?Is that not the same as imag==0.0?
Is there a difference?
If someone can explain the maths in this,it would be a great help.
thanks in advance
harry.