2.12 Calculating Cosines, Sines, and Tangents


You want more trigonometry functions than are available in other languages such as C and Perl.

Technique

PHP has a plethora of trigonometry functions, including acos() , asin() , atan() , atan2() , cos() , sin() , and tan() :

 <?php // $num will be the arc cosine of .5 // (the angle that yields a cos of .5) $num = acos (.5); // $num will be the arc sine of .5 // (the angle that yields a sine of .5) $num = asin (.5); // $num will be the arc tangent of .5 // (the angle that yields a tan of .5) $num = atan (.5); // $num is the arc tangent of .5 and .67 $num = atan2 (.5, .67); // $num is the sin of  P  $num = sin (M_PI); // $num is the cosine of  P  $num = cos (M_PI); // $num is the tangent of  P  $num = tan (M_PI); ?> 

Comments

The atan2() function is the same as atan((.5)/(.67)) , except that the quadrant of the result is accurate (and, therefore, so is the sign).



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