PHP rad2deg() function
The rad2deg()
function in PHP is used to convert an angle from radians to degrees. This function is useful when working with angles that are typically expressed in degrees, but were calculated or measured in radians.
Formula:
The mathematical relationship between radians and degrees is:
Where .
Syntax:
Parameters:
- $radians: The angle in radians that you want to convert to degrees.
Return Value:
- The function returns the equivalent value in degrees as a float.
Example 1: Converting Radians to Degrees
Output:
In this example, radians is equivalent to 180 degrees.
Example 2: Converting Radians
Output:
Here, radians is equivalent to 90 degrees.
Practical Usage:
- The
rad2deg()
function is helpful when working with angles in radians that need to be converted to degrees for readability, user interfaces, or situations where degrees are more commonly used. - It is often paired with trigonometric functions (such as
sin()
,cos()
,tan()
) which may return angles in radians, and then you can convert those to degrees for easier understanding.
Example 3: Using rad2deg()
After a Trigonometric Calculation
Output:
Summary:
rad2deg()
converts an angle from radians to degrees.- It’s useful in situations where angles calculated in radians (such as those from trigonometric functions) need to be converted to degrees for interpretation or display.