phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


PHP - Number: Calculating Trigonometric Values

Tag: number. calculation, trigonometric   Category: PHP Basic
post: 16 Mar 2008 read: 41


PHP Number Tips - Part 17: You want to perform a trigonometric calculation such as finding the sine or cosine of an angle. So, in order to do this, you have to use PHP's numerous trigonometric functions:

<?php
//define angle
$angle = 45;

//calculate sine
//result: "Sine: 0.850903524534 "
$sine = sin($angle);
echo "Sine: $sine \n";

//calculate cosine
//result: "Cosine: 0.525321988818 "
$csine = cos($angle);
echo "Cosine: $csine \n";

//calculate tangent
//result: "Tangent: 1.61977519054 "
$tangent = tan($angle);
echo "Tangent: $tangent \n";

//calculate arc sine
//result: "Arc sine: -1.#IND "
$arcSine = asin($angle);
echo "Arc sine: $arcSine \n";

//calculate arc cosine
//result: "Arc cosine: -1.#IND "
$arcCsine = acos($angle);
echo "Arc cosine: $arcCsine \n";

//calculate arc tangent
//result: "Arc tangent: 1.54857776147 "
$arcTangent = atan($angle);
echo "Arc tangent: $arcTangent \n";

//calculate hyperbolic sine
//result: "Hyperbolic sine: 1.74671355287E+019 "
$hypSine = sinh($angle);
echo "Hyperbolic sine: $hypSine \n";

//calculate hyperbolic cosine
//result: "Hyperbolic cosine: 1.74671355287E+019 "
$hypCsine = cosh($angle);
echo "Hyperbolic cosine: $hypCsine \n";

//calculate hyperbolic tangent
//result: "Hyperbolic tangent: 1 "
$hypTangent = tanh($angle);
echo "Hyperbolic tangent: $hypTangent \n";
?>

PHP comes with a rich toolkit of functions designed specifically to assist in trigonometry and with this functions, you can calculate sines, cosines, and tangents for any angle. While there aren't yet built-in functions to calculate secants, cosecants, and cotangents, it's fairly easy to calculate these inversions with the functions that are available.




| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting