lotrfan Posted October 3, 2007 Share Posted October 3, 2007 Hi All, Here's the code. Code: $side_a = $_REQUEST[side_a]; $side_b = $_REQUEST[side_b]; $side_c = $_REQUEST[side_c]; $angle_a = $_REQUEST[angle_a]; $angle_b = $_REQUEST[angle_b]; $angle_c = $_REQUEST[angle_c]; $side[0]=$side_a; $side[1]=$side_b; $side[2]=$side_c; $angle[0]=$angle_a; $angle[1]=$angle_b; $angle[2]=$angle_c; SAS($side, $angle); function SAS($side, $angle){ if (empty($side[0])) { $side[0] = sqrt((($side[1]*$side[1])+($side[2]*$side[2]))-(2*$side[1]*$side[2]*cos($angle[0]))); echo "<BR>" ,$side[0], " ";} if (empty($side[1])) { $side[1] = sqrt((($side[0]*$side[0])+($side[2]*$side[2]))-(2*$side[0]*$side[2]*cos($angle[1]))); echo "<BR>" ,$side[1], " "; } if (empty($side[2])) { $side[2] = sqrt((($side[0]*$side[0])+($side[1]*$side[1]))-(2*$side[0]*$side[1]*cos($angle[2]))); echo "<BR>" ,$side[2], " "; } } Here the user has input into a form (whose information is taken by $_REQUEST): --> "1" for side a --> "1" for side b --> "90" for angle C Here's my question...I've solved this problem out with a calculator. When a Side-Angle-Side has values of 1, 90 degrees, and 1 (respectively) the last side should be about "1.4142135623730950488016887242097". Yet when I use this function (which is the Law of Cosines) my browser displays "1.70180704907" as an answer. I think that my function may be faulty -- I'm trying to pass array values into a function -- and I don't know if it is working.... ***I know this is a very involved question...so I know that this is a lot to ask. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted October 3, 2007 Share Posted October 3, 2007 all the trig functions in php default to having a radian measurement. It could be that your measurements are in deg so use deg2rad on all measurements first to convert them to radians. Quote Link to comment Share on other sites More sharing options...
lotrfan Posted October 3, 2007 Author Share Posted October 3, 2007 Ah, I see. You are saying that when I use the cosine function, that instead of "90" degrees -- it is thinking that it is "90" radians... That would actually make perfect sense, and I can't believe I didn't think of something like that. Would I change it something like this? $angle[0] = deg2rad($angle[0]); Thanks again. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted October 4, 2007 Share Posted October 4, 2007 you have a few options, you can make a bool switch saying if measuremeants are rads or degrees and based on then work on that or just make the assumption that all are in degrees as only time you use radians is when you calculate a value in a calc class really. Of couse when you assume well you make a (assOUTOFuANDme) if you get the point Quote Link to comment Share on other sites More sharing options...
btherl Posted October 4, 2007 Share Posted October 4, 2007 Ah, I see. You are saying that when I use the cosine function, that instead of "90" degrees -- it is thinking that it is "90" radians... That would actually make perfect sense, and I can't believe I didn't think of something like that. Would I change it something like this? $angle[0] = deg2rad($angle[0]); Thanks again. Yep. Check this page Quote Link to comment Share on other sites More sharing options...
lotrfan Posted October 4, 2007 Author Share Posted October 4, 2007 OK, but if I change "90" from radians to degrees (which is good because I want them in degrees) the PHP converts "90 radians" into degrees -- which still is not correct. How do I set the variable that the user inputs (from the very start) to be a degree value instead? I've tried to search the PHP manual, but I can't seem to find anything. Thanks for your time. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted October 4, 2007 Share Posted October 4, 2007 <?php $input = 90; $input = deg2rad($input); //$input = pi/2 ?> if its in rads and you convert it you will get a realyl wrong nubmer Quote Link to comment Share on other sites More sharing options...
lotrfan Posted October 4, 2007 Author Share Posted October 4, 2007 Exactly! So the way to do it would be to have the variable set from the start to be used as a degree, correct? Quote Link to comment Share on other sites More sharing options...
corbin Posted October 4, 2007 Share Posted October 4, 2007 No. The most user friendly way would be to ask the user which form they're entering it as. For example, in the other thread about this topic (grr two threads! ;p), I posted a script with a radio button where a user may say if the number entered is degree or radian.... Then, if you know the entered number is degrees, you convert it to radians, but if it's in radians, you just leave it alone ;p. Quote Link to comment Share on other sites More sharing options...
lotrfan Posted October 4, 2007 Author Share Posted October 4, 2007 Sorry about the two threads...I thought I'd try to get a couple different perspectives from each of the forums -- little did I know that the users here would be so interdisciplinary in their PHP knowledge! But yes, I will adapt something like the radio method you used and make it a user's choice. It will also make it more user-friendly and applicable. Thanks all (especially to corbin for working two posts at once, lol) Quote Link to comment Share on other sites More sharing options...
Barand Posted October 4, 2007 Share Posted October 4, 2007 little did I know that the users here would be so interdisciplinary in their PHP knowledge! It's not a matter of being "interdisciplinary". It wastes peoples time answering a question in one forum that has already been answered in another. It's a simple rule - don't double post. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted October 5, 2007 Share Posted October 5, 2007 Edit: ignore Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.