如何使用C#Complex将矩形转换为极性形式

时间:2012-12-02 17:50:23

标签: c#

尝试将数字从矩形转换为极性形式,即从20 + j25到32 <38.66

这是我到目前为止所拥有的:

    static void Main(string[] args)
    {
        Complex A = new Complex (0.4, 0.3);
        Complex B = new Complex (0.6, 0.7);
        Complex C = new Complex (24, 19);
        Complex D = A + B + C;

        Console.WriteLine (D);

        Console.ReadLine();
    }

这给了我答案20,25。这是矩形的。我将如何制作这个极地?

由于

编辑: 好的,我做了一些改动,但仍然无法得到正确的答案。使用代码:

    static void Main(string[] args)
    {
        Complex RA = new Complex(25, 20);
        Console.WriteLine("{0} + i{1}", RA.Real, RA.Imaginary);

        double r, q;
        r = Math.Sqrt((RA.Real * RA.Real) + (RA.Imaginary * RA.Imaginary));
        q = Math.Atan(RA.Imaginary/RA.Real);
        Console.WriteLine("{0} < {1}", r, q);
        Console.ReadLine();
    }

我得到32&lt; 0.647 ......答案应为32 <38.66。任何人都可以解释为什么我的错误角度? 感谢

1 个答案:

答案 0 :(得分:0)

知道了。必须将弧度转换为度数。感谢大家的帮助!

    static void Main(string[] args)
    {
        Complex RA = new Complex(25, 20);
        Console.WriteLine("{0} + i{1}", RA.Real, RA.Imaginary);

        double r, q, z;
        r = Math.Sqrt((RA.Real * RA.Real) + (RA.Imaginary * RA.Imaginary));
        q = Math.Atan(RA.Imaginary/RA.Real);
        z = (q * (180/Math.PI));
        Console.WriteLine("{0} < {1}", r, z);
        Console.ReadLine();
    }