Open In App

PHP deg2rad() Function

Improve
Improve
Like Article
Like
Save
Share
Report

Among the methods to measure angles, the two most commonly used are degrees and radians. Students typically learn about degree while learning about radian becomes a later concern. But there are certain cases where radian is the preferred unit of measurement such as:

  • While working with the derivatives of trigonometric functions, it is preferable to use the radian measure for angles, because then derivative are easier as the pi is avoided.
  • In order to derive the relation between linear velocity and angular velocity for any motion in a circle, while using the radian measurement it produces the velocity in natural units i.e. m/s but if we use degrees then we get the velocity in the unit of m.degree/s which has to undergone through another conversion to be in natural form.

Thus in some cases it is required to convert from degrees to radian, this is where the method deg2rad() comes in aid.

Syntax:

float deg2rad ($value)

Parameters: The function takes a single parameters which is a float that represents the angle in degrees.

Return Type: This function returns a float value that represents the radian equivalent of the angle.

Examples:

Input :  $deg = 45;
Output : 0.78539816339745

Input : $deg = 90;
Output : 1.5707963267949

Input : $deg = 180;
Output : 3.1415926535898
         

Below program illustrates the working of deg2rad() in PHP:




<?php
// PHP code to illustrate the working of deg2rad()
$deg = 22.5;
$k = 8;
for(;$k>=1;$k/=2, $deg*=2)
{
  if($k!=1)
   echo 'pi/'.$k.' = '.deg2rad($deg).'<br>';
  else
   echo 'pi = '.deg2rad($deg).'<br>';
}
  
?>


Output:

pi/8 = 0.39269908169872
pi/4 = 0.78539816339745
pi/2 = 1.5707963267949
pi = 3.1415926535898

Important points to note:

  • It calculates the Radian equivalent of the angle given in degrees.
  • The counterpart of the method is deg2rad().
  • This method produces highly accurate results but is not much time efficient.

Reference:
http://php.net/manual/en/function.deg2rad.php


Last Updated : 22 Jun, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads