/// <summary> /// Method to get the smallest equivalent angle /// </summary> /// <param name="angle">The angle to simplify</param> /// <returns>The angle simplified</returns> public static double GetEquivalentAngle(double angle) { while (Arithmetic.GetAbsoluteValue(angle) >= 2 * Constants.PI) { angle -= 2 * Constants.PI * Arithmetic.GetSignOfNumber(angle); } return(angle); }
/// <summary> /// Method to get the magnitude of a vector /// </summary> /// <param name="vector">A double vector</param> /// <returns>The magnitude of the vector as a double</returns> static public double GetMagnitude(double[] vector) { double magnitude = 0; for (int i = 0; i < vector.Length; i++) { magnitude += Arithmetic.ElevateToPower(vector[i], 2); } return(Arithmetic.GetRootValue(2, magnitude)); }
/// <summary> /// Method to get the cosine of an angle /// </summary> /// <param name="angle">Angle in radians</param> /// <returns>Cosine of the angle</returns> public static double GetCos(double angle) { angle = GetEquivalentAngle(angle); double result = 0; for (int i = 0; i < 5; i++) { result += Arithmetic.ElevateToPower(-1, i) * Arithmetic.ElevateToPower(angle, 2 * i) / Arithmetic.GetFactorial(2 * i); } return(result); }
/// <summary> /// Method to get the determinant of the matrix /// </summary> /// <param name="matrix">A double matrix</param> /// <returns>The determinant</returns> static public double GetDeterminant(double[,] matrix) { int[] matrixDimension = checkMatrixDimensions(matrix); double result = 0; if (matrixDimension[0] == matrixDimension[1]) { if (matrixDimension[0] == 2) { result = matrix[0, 0] * matrix[1, 1] - matrix[0, 1] * matrix[1, 0]; return(result); } for (int i = 0; i < matrixDimension[0]; i++) { result += Arithmetic.ElevateToPower(-1, i) * matrix[0, i] * GetDeterminant(ConstructSubmatrix(matrix, 0, i)); } return(result); } return(1111110); }
/// <summary> /// Method to get the average of a set of numbers /// </summary> /// <param name="numberSet">Array of doubles</param> /// <returns>Average of the array numbers</returns> public static double GetAverage(double[] numberSet) { return(Arithmetic.AddDecimalNumbers(numberSet) / numberSet.Length); }
/// <summary> /// Method to get the perimeter of any shape /// </summary> /// <param name="sides">Array with lengths of all sides</param> /// <returns>Perimeter of the shape</returns> public static double GetGenericPerimeter(double[] sides) { return(Arithmetic.AddDecimalNumbers(sides)); }
/// <summary> /// Method to get the area of a square with its side /// </summary> /// <param name="side">The side of the square</param> /// <returns>Area of the square</returns> public static double GetSquareArea(double side) { return(Arithmetic.ElevateToPower(side, 2)); }
/// <summary> /// Method to get the area of a circle /// </summary> /// <param name="radius">The length of the radius</param> /// <returns>Area of a circle</returns> public static double GetCircleArea(double radius) { return(Convert.ToDouble(Constants.PI) * Arithmetic.ElevateToPower(radius, 2)); }
/// <summary> /// Method to get the volume of a sphere /// </summary> /// <param name="radius">The length of the radius</param> /// <returns>Volume of the sphere</returns> public static double GetSphereVolume(double radius) { return(4.0 / 3.0 * Arithmetic.ElevateToPower(radius, 3) * Constants.PI); }
/// <summary> /// Method to get the volume of a cube /// </summary> /// <param name="side">The length of a side of the cube</param> /// <returns>Volume of a cube</returns> public static double GetCubeVolume(double side) { return(Arithmetic.ElevateToPower(side, 3)); }
/// <summary> /// Method to calculate distance between two points /// </summary> /// <param name="x1">The x value of the first point</param> /// <param name="y1">The y value of the first point</param> /// <param name="x2">The x value of the second point</param> /// <param name="y2">The y value of the second point</param> /// <returns>The distance between the two points</returns> static public double GetDistanceBetweenTwoPoints(double x1, double y1, double x2, double y2) { double deltaX = x2 - x1; double deltaY = y2 - y1; return(Arithmetic.GetRootValue(2, (Arithmetic.ElevateToPower(deltaX, 2) + Arithmetic.ElevateToPower(deltaY, 2)))); }