BlackWaspTM

This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

.NET Framework
.NET 1.1+

.NET Math Library

The .NET framework includes a class named "Math", which provides a number of standard mathematical functions, using static methods, and mathematical values, using simple constants. This article describes all of the Math class members.

Asin

Asin calculates the arcsine of a value. Arcsine is the inverse of sine. Sine calculates the ratio of the opposite side and the hypotenuse of a triangle, based upon an angle. Arcsine does the opposite; the arcsine of the ratio gives the angle. As with Sin, Cos and Tan, Asin accepts a double argument and returns a double.

The following sample obtains an angle based upon the lengths of the opposing side and the hypotenuse. The ratio is calculated by simple division. The result is not exactly correct due to rounding errors and because the 0.6433 radians mentioned earlier was also an approximation.

static void Main()
{
    double angle = GetAngle(4, 5);  // angle = 0.6435
}

static double GetAngle(double opposite, double hypotenuse)
{
    return Math.Round(Math.Asin(opposite / hypotenuse), 4);
}

Acos

Acos calculates the arccosine of a number. This is the angle whose cosine is the provided value and is also known as the inverse cosine. We can use it as follows to calculate an angle from a right-angled triangle, measured in radians, from the lengths of the adjacent side and the hypotenuse.

static void Main()
{
    double angle = GetAngle(4, 5);  // angle = 0.6435
}

static double GetAngle(double adjacent, double hypotenuse)
{
    return Math.Round(Math.Acos(adjacent / hypotenuse), 4);
}

Atan

Atan completes the inverse functions for sine, cosine and tangent by calculating the arctangent. This is the angle, in radians, whose tangent is the provided value. In the sample below we use it to calculate an angle of a right-angled triangle using the opposite and adjacent sides without knowing the length of the hypotenuse.

static void Main()
{
    double angle = GetAngle(3, 4);  // angle = 0.6435
}

static double GetAngle(double opposite, double adjacent)
{
    return Math.Round(Math.Atan(opposite / adjacent), 4);
}

Atan2

Atan2 provides a variation on the Atan method. It produces the same results but rather than pre-calculating the ratio of the opposite and adjacent sides, we supply the two parts of the ratio to the method's two parameters. This means that Atan(0.75) is equal to Atan2(3, 4).

static void Main()
{
    double angle = GetAngle(3, 4);  // angle = 0.6435
}

static double GetAngle(double opposite, double adjacent)
{
    return Math.Round(Math.Atan2(opposite, adjacent), 4);
}

Sinh

Sinh is used to calculate the hyperbolic sine of an angle. The hyperbolic functions are used to express the relationship between the distance of a point on a hyperbola and the co-ordinate axis when plotted on a graph. The formula for hyperbolic sine is related to the exponential functions. The formula is:

Sinh forumula

double sinh = Math.Sinh(1); // sinh = 1.1752011936438014

Cosh

Cosh calculates hyperbolic cosine of an angle. The formula for hyperbolic cosine is:

Cosh forumula

double cosh = Math.Cosh(1); // cosh = 1.5430806348152437

Tanh

Tanh is the third of the hyperbolic functions supported by the Math class. As the name suggests, Tanh calculates the hyperbolic tangent for an angle, which is the ratio between the hyperbolic sine and hyperbolic cosine of the same angle:

Cosh forumula

By definition, the hyperbolic tangent can also be expressed using the constant e:

Cosh forumula

double tanh = Math.Tanh(1);  // tanh = 0.76159415595576485
7 October 2011