C# 中的三角函式


C# 中的三角函式包括 ACos、ASin、Sin、Cos、Tan 等。它屬於 System 名稱空間中的 Math 型別。

以下示例展示瞭如何在 C# 中實現三角函式 −

示例

 即時演示

using System;

class Program {
   static void Main() {
      Console.WriteLine(Math.Acos(0));
      Console.WriteLine(Math.Cos(2));

      Console.WriteLine(Math.Asin(0.2));
      Console.WriteLine(Math.Sin(2));

      Console.WriteLine(Math.Atan(-5));
      Console.WriteLine(Math.Tan(1));
   }
}

輸出

1.5707963267949
-0.416146836547142
0.201357920790331
0.909297426825682
-1.37340076694502
1.5574077246549

上面我們看到了使用 Asin 的逆正弦值 −

Math.Asin(0.2)

然後,我們還看到了使用 Acos 的反餘弦值 −

Math.Acos(0)

同樣,我們還找到了 Tan(1)、Atab(-5)、Sin(2) 和 Cos(2) 的值。

更新日期: 20 年 6 月 20 日

2K+ 瀏覽量

開啟你的職業生涯

完成課程,獲得認證

開始
廣告
© . All rights reserved.