The acos()
function in PHP returns the arc cosine (inverse cosine) of a number.
It accepts a float between -1 and 1 and returns the angle in radians.
This is useful in trigonometry to calculate angles when the cosine value is known.
The result will always be between 0 and π (0 to 3.14159…).
You can convert the result to degrees using rad2deg()
if needed.
Syntax
acos(float $num): float
$num
: Must be between -1 and 1- Returns the arc cosine of the number (in radians)
File Name: acos-example.php
<?php
echo acos(1); // ➤ 0 radians
echo "\n";
echo acos(0); // ➤ 1.5707963267949 (π/2)
echo "\n";
echo acos(-1); // ➤ 3.1415926535898 (π)
?>
Convert Radians to Degrees
$angle = acos(0); // π/2 radians
$degrees = rad2deg($angle); // ➤ 90 degrees
echo $degrees;
Use Cases
- Trigonometry calculations
- Geometry (e.g., angle between vectors)
- Signal processing and physics formulas
Summary
Function | Description |
---|---|
acos() |
Returns arc cosine (inverse cosine) in radians |
Range | Accepts values between -1 and 1 |
Output | Returns float value in radians |