Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
PHP deg2rad() Function
The deg2rad() function in PHP converts angles from degrees to radians. This function is essential when working with trigonometric functions like sin(), cos(), and tan(), which require angle arguments in radians rather than degrees.
Syntax
deg2rad(float $number) : float
Parameters
| Parameter | Description |
|---|---|
| number | A float number representing angle in degrees |
Return Value
Returns a float number representing the angle in radians. The conversion follows the formula: radians = degrees × ?/180.
Example
Here's how to convert degrees to radians using deg2rad() −
<?php
$degrees = 45;
$radians = deg2rad($degrees);
echo "deg2rad(" . $degrees . ") = " . $radians . "
";
// Common angle conversions
echo "30 degrees = " . deg2rad(30) . " radians
";
echo "90 degrees = " . deg2rad(90) . " radians
";
echo "180 degrees = " . deg2rad(180) . " radians
";
?>
deg2rad(45) = 0.78539816339745 30 degrees = 0.52359877559830 radians 90 degrees = 1.5707963267949 radians 180 degrees = 3.1415926535898 radians
Practical Application
The function is commonly used with trigonometric calculations −
<?php
$angle_degrees = 60;
$angle_radians = deg2rad($angle_degrees);
echo "Angle: " . $angle_degrees . " degrees
";
echo "Sin(" . $angle_degrees . "°) = " . sin($angle_radians) . "
";
echo "Cos(" . $angle_degrees . "°) = " . cos($angle_radians) . "
";
echo "Tan(" . $angle_degrees . "°) = " . tan($angle_radians) . "
";
?>
Angle: 60 degrees Sin(60°) = 0.86602540378444 Cos(60°) = 0.5 Tan(60°) = 1.7320508075689
Conclusion
The deg2rad() function is essential for mathematical calculations involving trigonometry. Use it whenever you need to convert degree measurements to radians for PHP's trigonometric functions.
Advertisements
