rsharshar / aforge

Automatically exported from code.google.com/p/aforge
Other
0 stars 0 forks source link

Complex.Phase is slightly incorrect (or at least non-standard) #271

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a new complex number, such as z = (-5 + 1i)
2. Compute its phase. AForge will produce ~ -0.1973 as result.
3. As far as I know, the result should have been ~ 2.9442. Since (Im(z) = 1) > 
Re(z) = -5), the phase should be atan(1/-5)+pi ~ 2.9442.

What is the expected output? What do you see instead?

The following snippet reproduces the problem:

Complex complex = new Complex(-5, 1);
double actual = complex.Phase; // -0.1973
double expected = Math.Atan2(complex.Im, complex.Re); // 2.9441

What version of the product are you using?
AForge.NET 2.2.3

Please provide any additional information below.
The solution is to use Atan2 instead of Atan in Complex.Phase calculation. In 
Complex.cs, where it reads:

        public double Phase
        {
            get { return System.Math.Atan( Im / Re ); }
        }

I suppose it should be:

        public double Phase
        {
            get { return System.Math.Atan2( Im, Re ); }
        }

Regards,
Cesar

Original issue reported on code.google.com by cesarso...@gmail.com on 27 Dec 2011 at 6:51

GoogleCodeExporter commented 8 years ago

Original comment by andrew.k...@gmail.com on 27 Dec 2011 at 10:31

GoogleCodeExporter commented 8 years ago
Fixed Complex.Phase property, so it provides proper value for cases when real 
part is less than zero.

Committed in revision 1651. Will be released in version 2.2.4+

Original comment by andrew.k...@gmail.com on 27 Dec 2011 at 10:35

GoogleCodeExporter commented 8 years ago

Original comment by andrew.k...@gmail.com on 23 Feb 2012 at 9:11