deg2rad(): Convert Degree to Radian

deg2rad(X);
X is the number representing angular value in degree.
<?Php
echo deg2rad(0); // Output is 0
echo "<br>";
echo deg2rad(90); // Output  1.5707963267949
echo "<br>";
echo deg2rad(180); // Output is 3.1415926535898
echo "<br>";
echo deg2rad(270); // Output is 4.7123889803847 
?>

deg2rad() with round()

We can use round() to remove extra decimal places.
<?Php
echo round(deg2rad(90),2); // Output  is 1.57
?>

deg2rad() with sin() cos()

Decimal places Sin(), cos() and other trigonometric functions takes input in radian so while using if we are using data in degree then we have to convert them first and then use with Sin() , Cos() etc.
<?Php
echo sin(deg2rad(90)); // Output  is 1
?>
Let us try few more examples
<?Php
echo sin(deg2rad(0)); // Output  is 0
echo "<br>";
echo round(sin(deg2rad(180))); // Output  is 0
echo "<br>";
echo sin(deg2rad(270)); // Output  is -1
echo "<br>";
echo cos(deg2rad(0)); // Output  is 1
echo "<br>";
echo cos(deg2rad(180)); // Output  is -1
echo "<br>";
echo tan(deg2rad(45)); // Output  is 1
?>

Plotting of SIN & COS curves by using PHP GD function with deg2rad()

Your Rating




Google+

Post Comment This is for short comments only. Use the forum for more discussions.




HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2018 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer