This C# program demonstrates how to use the trigonometric math functions in C#.
using System;
namespace XoaX {
class Program {
static void Main(string[] args) {
double dTheta = (2.0 * Math.PI) / 3.0;
double dX = Math.Cos(dTheta);
double dY = Math.Sin(dTheta);
double dTan = Math.Tan(dTheta);
Console.WriteLine("2*Pi/3 = " + dTheta);
Console.WriteLine("The Cos of " + dTheta + " is " + dX);
Console.WriteLine("The Sin of " + dTheta + " is " + dY);
Console.WriteLine("The Tan of " + dTheta + " is " + dTan);
// Theta is in the range of Acos(): [0, Math.PI]
Console.WriteLine("The Acos of " + dX + " is " + Math.Acos(dX));
// Theta is not in the range of Asin(): [-Math.PI/2, Math.PI/2]
Console.WriteLine("The Asin of " + dY + " is " + Math.Asin(dY));
// Theta is not in the range of Asin(): (-Math.PI/2, Math.PI/2)
Console.WriteLine("The Atan of " + dTan + " is " + Math.Atan(dTan));
// Theta is in the range of Atan2(): [0, 2*Math.PI]
Console.WriteLine("The Atan2 of " + dX + " and " + dY + " is " + Math.Atan2(dY, dX));
}
}
}
2*Pi/3 = 2.0943951023932 The Cos of 2.0943951023932 is -0.5 The Sin of 2.0943951023932 is 0.866025403784439 The Tan of 2.0943951023932 is -1.73205080756888 The Acos of -0.5 is 2.0943951023932 The Asin of 0.866025403784439 is 1.0471975511966 The Atan of -1.73205080756888 is -1.0471975511966 The Atan2 of -0.5 and 0.866025403784439 is 2.0943951023932 Press any key to continue . . .
© 20072025 XoaX.net LLC. All rights reserved.