2.11 Converting Between Radians and Degrees


You want to do your trigonometry functions in degrees not radians.

Technique

Convert between degrees and radians:

 <?php $num1 = 90; $num2 = 3.14; $rad = deg2rad ($num1); $deg = rad2deg ($num2); print "The value of $num1 degrees in radians is $rad\n"; print "and the value of $num2 radians is $deg degrees"; ?> 

Comments

The deg2rad() and rad2deg() functions can be used to convert a number from degrees to radians and back again. This can be very useful if you want to find the cosine of a number that is in degrees. You can use the deg2rad() function to convert the number and then use the cos() function on the result:

 <?php $cos_60 = cos (deg2rad (60)); ?> 


PHP Developer's Cookbook
PHP Developers Cookbook (2nd Edition)
ISBN: 0672323257
EAN: 2147483647
Year: 2000
Pages: 351

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net