atan() : the arc tangent (inverse tangent) of a given number

<?Php
echo atan(0); // Output is 0
echo "<br>";
echo atan(1); // Output  0.78539816339745
echo "<br>";
echo atan(-1); // -0.78539816339745
echo "<br>";
echo atan(4); // Output is 1.325817663668
echo "<br>";
echo atan(2); // Output is 1.1071487177941
echo "<br>";
echo atan(90); // Output is 1.5596856728973
?>
atan(X);
X is the angular value in radian. We get output as ARC tangent of the input angle.

deg2rad() with atan()

We can use deg2rad() to convert Degree value to radian and then use atan().
<?Php
echo atan(deg2rad(45)); // Output 0.66577375002835
echo "<br>";
echo atan(deg2rad(90)); // Output 1.0038848218539
echo "<br>";
echo atan(deg2rad(180)); // Output 1.2626272556789
echo "<br>";
echo atan(deg2rad(1)); // Output 0.017451520651466
echo "<br>";
echo atan(deg2rad(-1)); // Output -0.017451520651466
echo "<br>";
echo atan(deg2rad(-4)); // Output -0.069700080299613
echo "<br>";
echo atan(deg2rad(-90)); // Output -1.0038848218539
echo "<br>";
echo atan(deg2rad(-180)); // Output -1.2626272556789
?>

Example: Calculating Angle in a Triangle

$opposite = 5;
$adjacent = 10;
$angle = atan($opposite / $adjacent);  // Result in radians
$angle_in_degrees = rad2deg($angle);
echo $angle_in_degrees;  // Output: 26.565 degrees

Example: Handling Edge Cases

echo atan(0);  // Output: 0
echo atan(-1);  // Output: -0.785398163 (negative angle)

Example: Comparing atan() and atan2()

$y = 5;
$x = 10;
echo atan($y / $x);  // Output: 0.463 radians

// Using atan2 to handle full quadrant angles
echo atan2($y, $x);  // Output: 0.463 radians (same, but handles quadrant correctly)
Explanation:
Triangle Calculation: Demonstrates a practical application for calculating angles from side lengths.
Edge Case Handling: Explains what happens when input values are zero or negative.
Comparison: Clarifies when `atan()` or `atan2()` should be used for handling angles in different quadrants.

Questions

MIN() function
Math Functions
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com











    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer