php_joe Posted March 21, 2007 Share Posted March 21, 2007 Hi, I'm having some problems with a math function not giving me the answer that I expect. Wikipedia says that you can find a side of a triangle if you know an angle and 2 sides using the law of cosine: http://en.wikipedia.org/wiki/Law_of_cosines so I used this code: <? $a = '5'; $b = '5'; $c = sqrt(pow($a, 2) + pow($b, 2) - (2 * $a * $b * cos(135))); echo "$c"; ?> And it gave me the correct (I think) answer: 9.9902148003463 But when I try to find a side using 2 angles and a side using the law of sine it doesn't work. The equation that I have is "b = (12 Sin 65)/(sin 50)" from http://home.alltel.net/okrebs/page93.html so I used this code: <? $b = 12 * sin(65) / sin(50); echo "$b"; ?> Which, according the the website that I got it from, should have printed "14.2", but I got "-37.815911143213" instead. What am I doing wrong? Link to comment https://forums.phpfreaks.com/topic/43644-wrong-solution-with-sin-solved/ Share on other sites More sharing options...
php_joe Posted March 21, 2007 Author Share Posted March 21, 2007 Nevermind, I got it. The correct method is: <? $b = 12 * sin(deg2rad(65)) / sin(deg2rad(50)); echo "$b"; ?> Link to comment https://forums.phpfreaks.com/topic/43644-wrong-solution-with-sin-solved/#findComment-211897 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.