MathF.Atan2(Single,Single)方法用于返回切线为两个指定数字的商的角度。基本上,它返回一个角度θ(以弧度为单位),该角度的值介于-π和π之间。这是正x轴和点(x,y)之间的逆时针角度。
Syntax: public static float Atan2 (float y, float x);
Parameters:
y: The y coordinate of a point of type System.Single.
x: The x coordinate of a point System.Single.
返回值:该方法返回System.Single类型的角度Θ。
注意:角度θ(以弧度为单位),使得-π≤θ≤π,且tan(θ)= value1 / value2,其中(value1,value2)是笛卡尔平面中的点。返回值有两个条件:
- 当点位于笛卡尔平面中时
- 当这些点位于象限的边界上时
范例1:
// C# program to demonstrate the
// MathF.Atan2(Single, Single) Method
using System;
class Geeks {
// Main method
public static void Main()
{
// using MathF.Atan2(Single, Single) Method
// and converting result into degree
Console.Write(MathF.Atan2(10f, 10f) * (180 / MathF.PI));
}
}
输出:
45
范例2:
// C# program to demonstrate the
// MathF.Atan2(Single, Single) Method
using System;
class Geeks {
// Main method
public static void Main()
{
// using MathF.Atan2(Single, Single) Method
// and converting result into degree
Console.Write(MathF.Atan2(0f, -7f) * (180 / MathF.PI));
}
}
输出:
180