The atan()
function in PHP returns the inverse tangent (arc tangent) of a number.
It outputs the angle in radians whose tangent is the given value.
The result lies between -π/2 and +π/2.
You can use it for trigonometric calculations, slope angles, or rotations.
Use rad2deg()
to convert the result into degrees if needed.
Syntax
atan(float $num): float
- $num: Any real number
- Returns: Arc tangent of the number in radians
- Range of result: from -π/2 to +π/2
File Name: atan-example.php
<?php
echo atan(1); // ➤ 0.78539816339745 (π/4 radians)
echo "\n";
echo atan(0); // ➤ 0
echo "\n";
echo atan(-1); // ➤ -0.78539816339745 (-π/4 radians)
?>
Convert Radians to Degrees
$angle = atan(1);
$degrees = rad2deg($angle); // ➤ 45
echo $degrees;
Use Cases
Use Case | Description |
---|---|
Trigonometry | Find angles based on slopes/tangent values |
Geometry | Used in triangle angle calculations |
Game Development/Graphics | Calculating direction/rotation |
Summary
Function | Description |
---|---|
atan() |
Returns arc tangent (in radians) |
Input | Any real number |
Output | Float between -π/2 and +π/2 |