C# 角度转换为弧度:简单方法和代码示例
在 C# 中,您可以使用 Math 类中的静态方法将角度转换为弧度。具体方法是使用 Math.PI 常量乘以角度除以 180。
示例代码如下:
using System;
class Program
{
static void Main(string[] args)
{
double degrees = 45;
double radians = degrees * Math.PI / 180;
Console.WriteLine('角度: ' + degrees);
Console.WriteLine('弧度: ' + radians);
}
}
输出结果为:
角度: 45
弧度: 0.785398163397448
注意:Math 类中的三角函数方法(如 Math.Sin、Math.Cos 等)接受的参数是弧度值。因此,在计算三角函数时,需要将角度转换为弧度。
原文地址: http://www.cveoy.top/t/topic/F1q 著作权归作者所有。请勿转载和采集!