To calculate an angle from a triangle's sides.
Use the 'law of cosines' :
<?php
// a²+b²-c²
// cosC = --------
// 2ab
function calculateAngle($c,$a,$b)
{
$angleInRadians=acos((pow($a,2) + pow($b,2) - pow($c,2)) / (2 * $a * $b));
return rad2deg($angleInRadians);
}
?>
$a, $b, $c are the triangle sides.
The function returns the angle opposite side c, in degrees.
Wednesday, December 26, 2007
Arc Cosine
POSTED BY
Oriol
AT
8:54 AM