C#|数学。Atan2()方法

数学Atan2() 是一个内置的数学类方法,它返回的角度的切线是两个指定数字的商。基本上,它返回一个角度θ(以弧度为单位),其值介于-π和π之间。这是正x轴和点(x,y)之间的逆时针角度。

null

语法:

public static double Atan2(double value1, double value2)

参数:

价值1: 类型点的y坐标 系统双重的 . 价值2: 类型点的x坐标 系统双重的 .

返回类型: 返回类型的角度Θ 系统双重的 .

注: 角θ(以弧度为单位),使得≤ θ ≤ π、 tan(θ)=value1/value2,其中(value1,value2)是笛卡尔平面上的点。返回值有两个条件:

  • 当点位于笛卡尔平面上时
  • 当点位于象限的边界上时

下面是演示数学的程序。当点 位于笛卡尔平面 :

  • 项目1: 如果点(值1,值2)位于第一象限,即0

    // C# program to demonstrate the
    // Math.Atan2() Method when point
    // lies in first quadrant
    using System;
    class Geeks {
    // Main method
    public static void Main()
    {
    // using Math.Atan2() Method &
    // converting result into degree
    Console.Write(Math.Atan2(10, 10) * (180 / Math.PI));
    }
    }

    
    

    输出:

    45
    

  • 项目2: 如果点(值1,值2)位于第二象限,即π/2

    // C# program to demonstrate the
    // Math.Atan2() Method when point
    // lies in second quadrant
    using System;
    class Geeks {
    // Main method
    public static void Main()
    {
    // using Math.Atan2() Method &
    // converting result into degree
    Console.Write(Math.Atan2(10, -10) * (180 / Math.PI));
    }
    }

    
    

    输出:

    135
    

  • 方案3: 如果点(值1,值2)位于第三象限,即-π

    // C# program to demonstrate the
    // Math.Atan2() Method when point
    // lies in third quadrant
    using System;
    class Geeks {
    // Main method
    public static void Main()
    {
    // using Math.Atan2() Method &
    // converting result into degree
    Console.Write(Math.Atan2(-10, -10) * (180 / Math.PI));
    }
    }

    
    

    输出:

    -135
    

  • 方案4: 如果点(值1,值2)位于第四象限,即-π/2

    // C# program to demonstrate the
    // Math.Atan2() Method when point
    // lies in fourth quadrant
    using System;
    class Geeks {
    // Main method
    public static void Main()
    {
    // using Math.Atan2() Method &
    // converting result into degree
    Console.Write(Math.Atan2(-10, 10) * (180 / Math.PI));
    }
    }

    
    

    输出:

    -45
    

下面是演示数学的程序。当点 位于象限的边界上 :

  • 项目1: 如果value1为0,value2不为负,即θ=0

    // C# program to demonstrate the
    // Math.Atan2() Method when value1
    // is 0 and value2 is not negative
    using System;
    class Geeks {
    // Main method
    public static void Main()
    {
    // using Math.Atan2() Method &
    // converting result into degree
    Console.Write(Math.Atan2(0, 10) * (180 / Math.PI));
    }
    }

    
    

    输出:

    0
    

  • 项目2: 如果value1为0,value2为负,即θ=π

    // C# program to demonstrate the
    // Math.Atan2() Method when value1
    // is 0 and value2 is negative
    using System;
    class Geeks {
    // Main method
    public static void Main()
    {
    // using Math.Atan2() Method &
    // converting result into degree
    Console.Write(Math.Atan2(0, -10) * (180 / Math.PI));
    }
    }

    
    

    输出:

    180
    

  • 方案3: 如果值1为正,值2为0,即θ=π/2

    // C# program to demonstrate the
    // Math.Atan2() Method value1 is
    // positive and value2 is 0
    using System;
    class Geeks {
    // Main method
    public static void Main()
    {
    // using Math.Atan2() Method &
    // converting result into degree
    Console.Write(Math.Atan2(10, 0) * (180 / Math.PI));
    }
    }

    
    

    输出:

    90
    

  • 方案4: 如果value1为负,value2为0,即θ=-π/2

    // C# program to demonstrate the
    // Math.Atan2() Method value1 is
    // negative and value2 is 0
    using System;
    class Geeks {
    // Main method
    public static void Main()
    {
    // using Math.Atan2() Method &
    // converting result into degree
    Console.Write(Math.Atan2(-10, 0) * (180 / Math.PI));
    }
    }

    
    

    输出:

    -90
    

  • 方案5: 如果value1为0,value2为0,即θ=0

    // C# program to demonstrate the
    // Math.Atan2() Method value1 is
    // 0 and value2 is 0
    using System;
    class Geeks {
    // Main method
    public static void Main()
    {
    // using Math.Atan2() Method &
    // converting result into degree
    Console.Write(Math.Atan2(0, 0) * (180 / Math.PI));
    }
    }

    
    

    输出:

    0
    

要记住的要点: 如果value1或value2为 ,或者如果value1和value1 积极信心 负信心 ,该方法返回 .

例子:

// C# program to demonstrate the Math.Atan2()
// method when arguments are of type either
// NaN, PositiveInfinity or NegativeInfinity
using System;
class Geeks {
// Main method
public static void Main()
{
double val1 = 0;
double val2 = Double.NaN;
Console.WriteLine(Math.Atan2(val1, val2));
double val3 = Double.NaN;
double val4 = Double.NaN;
Console.WriteLine(Math.Atan2(val3, val4));
double val5 = Double.NaN;
double val6 = Double.PositiveInfinity;
Console.WriteLine(Math.Atan2(val5, val6));
double val7 = Double.PositiveInfinity;
double val8 = Double.NegativeInfinity;
Console.WriteLine(Math.Atan2(val7, val8));
}
}


输出:

NaN
NaN
NaN
NaN

参考: https://msdn.microsoft.com/en-us/library/system.math.atan2

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享