Open In App

PHP rad2deg() Function

Improve
Improve
Like Article
Like
Save
Share
Report

Measurement of Angle is one of the foundation stones of Geometry and Trigonometry, and the two most commonly used methods of measurement are Degrees and Radians. Because of it’s simplicity many prefer to use degree over Radian. Some of the reasons that makes degrees more preferable are:

  • Degrees may not be much efficient while calculating derivatives or complicated relations, but it is easy to understand and visualize.
  • While Radian is in fact a ratio, Degree is considered as the unit of rotational displacement where a complete rotation is equivalent to 360 Degrees. Because of this simplicity students are taught and are much more familiar to Degrees rather than Radians.

Thus in some cases we may require to convert from radians to degrees, this is where the method rad2deg() comes in aid.

Syntax:

float rad2deg($value)

Parameters: The function takes a single parameter $value which is of type float that represents an angle in Radians.

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

Examples:

Input :  $value = M_PI_4;
Output : 45

Input : $value = M_PI_2;
Output : 90

Input : $value = M_PI;
Output : 180
         

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




<?php
  
// PHP code to illustrate the working of rad2deg()
  
$rad = M_PI;
$k = 1;
  
for(;$k<=8;$k*=2, $rad/=2)
{
    if($k!=1)
       echo 'pi/'.$k.' = '.rad2deg($rad)."\n";
    else
       echo 'pi = '.rad2deg($rad)."\n";
}
  
?>


Output:

pi = 180
pi/2 = 90
pi/4 = 45
pi/8 = 22.5

Important points to note:

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

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


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