Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
math
tangent
communitycreator

What is atan() in PHP?

harris910

The atan() functionalso called the arc tangent function returns the inverse tangent of a number. To be more specific, atan() returns the inverse tangent of a number in radians.

This means that tan(atan(x)) would be equal to x.

Figure 1 shows the mathematical representation of the atan() function.

Figure 1: Mathematical representation of inverse tangent function

To convert radians to degrees, use:

degrees = radians * ( 180.0 / M_PI )

Below is the graphical representation of the atan function.

 Graphical representation of atan() function
Graphical representation of atan() function

Syntax

float atan(num)

Parameter

This function requires a number as a parameter.

Return value

atan() will return the inverse tangent of a number (in radians) that is sent as a parameter. The return value lies within [-pi/2,pi/2] radians.

Example

<?php
#Positive number in radians
echo("atan(0.5): ");
echo (atan(0.5));
echo(" Radians")
?>	
<?php
#Negative number in radians
echo("atan(-0.5): ");
echo (atan(-0.5));
echo(" Radians")
?>

<?php
#tan(atan(x))
echo("tan(atan(0.5)): ");
echo (tan(atan(0.5)));
echo(" Radians")
?>

<?php
#applying atan() and then converting the result in radians to degrees
#radians = 1
echo("atan(1) * (180.0 / M_PI)): ");
echo (atan(1) * (180.0 / M_PI));
echo(" Degrees")
?>

RELATED TAGS

php
math
tangent
communitycreator
RELATED COURSES

View all Courses

Keep Exploring