/NerdSharp.Net_Studio/NerdSharp_UberNet/Science/Math/Utils/Trigonometry.cs
C# | 269 lines | 235 code | 33 blank | 1 comment | 13 complexity | 1416e509f2dacb9199e7fc4d1ea01317 MD5 | raw file
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Numerics;
- using System.Runtime.Serialization;
- using System.ServiceModel;
- using M = System.Math;
- using System.Windows;
- using System.Windows.Shapes;
- using OthM = NerdSharp.Net_Studio.NerdSharp_UberNet.Science.Math.Utils.Math;
-
- namespace NerdSharp.Net_Studio.NerdSharp_UberNet.Science.Math.Utils
- {
- public class Trigonometry
- {
- [OperationContract]
- public static double degreesToRadians(double degrees)
- {
- return degrees * (M.PI / 180d);
- }
-
- [OperationContract]
- public static double Hypotenous(double a, double b)
- {
- return M.Sqrt(M.Pow(a, 2) + M.Pow(b, 2));
- }
-
- [OperationContract]
- public static double radToDeg(double rad)
- {
- return rad * (180d / M.PI);
- }
-
- [OperationContract]
- public static Point ConvertToScreenPoint(Point cartesian, Point screenOrigin)
- {
- Point answer = new Point();
- if (cartesian.Y < 0)
- {
- answer.Y = M.Abs(cartesian.Y) + screenOrigin.Y;
- }
- else if (cartesian.Y >= 0)
- {
- answer.Y = screenOrigin.Y - cartesian.Y;
- }
- answer.X = screenOrigin.X + cartesian.X;
- return answer;
- }
-
- [OperationContract]
- public static double VerSine(double theta)
- {
- return 0;
- }
-
- [OperationContract]
- public static double csc(double theta)
- {
- return 1 / System.Math.Sin(theta);
- }
-
- [OperationContract]
- public static double sec(double theta)
- {
- return 1 / System.Math.Cos(theta);
- }
-
- [OperationContract]
- public static double cot(double theta)
- {
- return 1 / System.Math.Tan(theta);
- }
-
- [OperationContract]
- public static double csch(double theta)
- {
- return 1 / System.Math.Sinh(theta);
- }
-
- [OperationContract]
- public static double sech(double theta)
- {
- return 1 / System.Math.Cosh(theta);
- }
-
- [OperationContract]
- public static double coth(double theta)
- {
- return 1 / System.Math.Tanh(theta);
- }
-
- [OperationContract]
- public static double acsc(double theta)
- {
- return 1 / System.Math.Asin(theta);
- }
-
- [OperationContract]
- public static double asec(double theta)
- {
- return 1 / System.Math.Acos(theta);
- }
-
- [OperationContract]
- public static double acot(double theta)
- {
- return 1 / System.Math.Atan(theta);
- }
-
- //#region inverse hyperbolic trig functions
- [OperationContract]
- public static double asinh(double theta)
- {
- if (!(System.Math.Abs(theta) < 1))
- {
- throw new Exception("Sorry, but inverse hyperbolic sine nees a value between -1 and 1 exclusive.");
- }
- double answer = 0;
- for (int i = 0; i < 1000; i++)
- {
- double paren1 = (System.Math.Pow(-1, i) * (double)OthM.Factorial(2 * i)) /
- ((System.Math.Pow(2, 2 * i) * System.Math.Pow((double)OthM.Factorial(i), 2)));
- double paren2 = System.Math.Pow(theta, (2 * i + 1)) / ((2 * i) + 1);
- answer += (paren1 * paren2);
- }
- return answer;
- }
-
- [OperationContract]
- public static double acosh(double theta)
- {
- if (!(theta > 1))
- {
- throw new Exception("Sorry but inverse hyperbolic cosine needs to have an input of greater than one");
- }
- double buffer = 0;
- for (int i = 0; i < 1000; i++)
- {
- double paren1 = (double)OthM.Factorial(2 * i) /
- ((System.Math.Pow(2, 2 * i) * System.Math.Pow((double)OthM.Factorial(i), 2)));
- double paren2 = System.Math.Pow(theta, (-2 * i)) / (2 * i);
- buffer = paren1 + paren2;
- }
- return System.Math.Log(2 * theta, System.Math.E) - buffer;
- }
-
- [OperationContract]
- public static double atanh(double theta)
- {
- if (!(System.Math.Abs(theta) < 1))
- {
- throw new Exception("");
- }
- double answer = 0;
- for (int i = 0; i < 1000; i++)
- {
- answer += System.Math.Pow(theta, (2 * i + 1)) / ((2 * i) + 1);
- }
- return answer;
- }
-
- [OperationContract]
- public static double acsch(double theta)
- {
- if (!(System.Math.Abs(theta) > 1))
- {
- throw new Exception("Sorry, but inverse hyperbolic cotangent needs to be greater than 1 or less than -1 exclusive.");
- }
- return 1 / asinh(theta);
- }
-
- [OperationContract]
- public static double asech(double theta)
- {
- if (!((theta > 0) || (theta < 1)))
- {
- throw new Exception("Sorry, but value for inverse hyberbolic secant needs to be between 0 and 1 exclusive.");
- }
- return 1 / acosh(theta);
- }
-
- [OperationContract]
- public static double acoth(double theta)
- {
- if (!(System.Math.Abs(theta) > 1))
- {
- throw new Exception("Sorry, but inverse hyperbolic cotangent needs to be greater than 1 or less than -1 exclusive.");
- }
- return 1 / atanh(theta);
- }
-
-
-
- #region other trigFunctions
- [OperationContract]
- public static double exsec(double theta)
- {
- return sec(theta) - 1;
- }
- #endregion
-
- #region complex trig functions
- [OperationContract]
- public static Complex csc(Complex theta)
- {
- return 1 / Complex.Sin(theta);
- }
-
- [OperationContract]
- public static Complex sec(Complex theta)
- {
- return 1 / Complex.Cos(theta);
- }
-
- [OperationContract]
- public static Complex cot(Complex theta)
- {
- return 1 / Complex.Tan(theta);
- }
-
- [OperationContract]
- public static Complex csch(Complex theta)
- {
- return 1 / Complex.Sinh(theta);
- }
-
- [OperationContract]
- public static Complex sech(Complex theta)
- {
- return 1 / Complex.Cosh(theta);
- }
-
- [OperationContract]
- public static Complex coth(Complex theta)
- {
- return 1 / Complex.Tanh(theta);
- }
-
- [OperationContract]
- public static Complex asinh(Complex theta, long places)
- {
- Complex answer = new Complex();
- answer = Complex.Log(theta + (Complex.Sqrt(Complex.Pow(theta, 2) + 1)), System.Math.E);
- return answer;
- }
-
- [OperationContract]
- public static Complex acosh(Complex theta, long places)
- {
- Complex answer = new Complex();
- answer = Complex.Log((theta + (Complex.Sqrt(theta + 1) * Complex.Sqrt(theta - 1))), System.Math.E);
- return answer;
- }
- #endregion
-
- #region CircleUtils
- public static double X(double thetaDegrees, double radius)
- {
- return M.Cos(degreesToRadians(thetaDegrees)) * radius;
- }
-
- public static double Y(double thetaDegrees, double radius)
- {
- return M.Sin(degreesToRadians(thetaDegrees)) * radius;
- }
- #endregion
- }
- }