PHP deg2rad() function in PHP
The deg2rad()
function in PHP is used to convert an angle from degrees to radians. In mathematics, radians are often used in trigonometric functions, and this function simplifies the conversion from degrees to radians.
Formula:
The mathematical relationship between degrees and radians is:
Where .
Syntax:
Parameters:
- $degrees: The angle in degrees that you want to convert to radians.
Return Value:
- The function returns the equivalent value in radians as a float.
Example 1: Converting Degrees to Radians
Output:
In this example, 180 degrees is equivalent to radians (approximately 3.1416).
Example 2: Converting 90 Degrees
Output:
In this case, 90 degrees is equivalent to radians (approximately 1.5708).
Practical Usage:
- The
deg2rad()
function is often used in calculations involving trigonometric functions such assin()
,cos()
, andtan()
, which typically expect the angle to be in radians. - When working with angles in degrees (for example, in geometry or engineering problems), this function simplifies the conversion.
Example 3: Using deg2rad()
with Trigonometric Functions
Output:
Summary:
deg2rad()
converts an angle from degrees to radians.- It’s useful in trigonometry, geometry, or any calculations where angles need to be converted to radians for functions that expect angles in radians.