SQL Server ACOS() Function

The ACOS() function is a mathematical function in SQL Server that returns the inverse cosine value (in radians) of a given number. The result of the function is a float value that represents the inverse cosine value of the given number.

Syntax

ACOS(number)

Parameter:

  • number: Required. The number for which to calculate the inverse cosine value. This value must be between -1 and 1.

Usage

The ACOS() function is commonly used to calculate inverse cosine values, and can be used in trigonometric-related calculations. For example, when calculating the angle between two vectors, this function can be used to calculate the quotient of the dot product and the product of their magnitudes, and then convert it to degrees.

Examples

Here are two examples of using the ACOS() function:

Example 1: Calculate the inverse cosine value of a given number

SELECT ACOS(0.5);

Output:

1.0471975511966

Example 2: Calculate the angle between two vectors using the ACOS() function

Assume that there are two vectors, A and B, with a dot product of 2, a magnitude of 5 for vector A, and a magnitude of 4 for vector B. The following SQL statement can be used to calculate the angle between them:

SELECT ACOS(2 / (5 * 4)) * 180 / PI();

Output:

32.189

Conclusion

The ACOS() function is a very useful mathematical function that can be used to calculate inverse cosine values. It can be used in trigonometric-related calculations, such as when calculating the angle between two vectors.