|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
|
_________________ Asati di tempari! |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Fri Oct 05, 2007 3:40 am |
The cosine of 90 radians isn't 0. Use math.rad to convert them first.
|
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Fri Oct 05, 2007 3:49 am |
He was working with me on behalf of coding a simple trig problem:
#ALAIS triangle {
#SAY {This will compute the the length of the third leg of a triangle given the the lengths of two legs and the connecting angle.}
#PROMPT $sideA "Enter the length of side A"
#PROMPT $sideB "Enter the length of side B"
#PROMPT $angleC "Enter the angle degree where side A and side B meet"
#SAY {Side c is @scalene($sideA,$sideB,$angleC)}
}
#FUNC scalene {
a = zs.param(1);
b = zs.param(2);
C = zs.param(3);
return math.sqrt(a^2 + b^2 - (2*a*b*math.cos(C)))
}
Make sure to set the func language to Lua...
for a=6 b=8 C=90 then c=10... but its returning 11.958890715631
PS how do you define a function's language from the command line? |
|
_________________ Discord: Shalimarwildcat |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Fri Oct 05, 2007 4:05 am |
You don't. You have to use XML.
Cor, it's been a while since I've done trig! And I don't have a real calculator to hand, so I can't check your answer for that one, but after adding math.rad like I suggested, it seems to be working.
print(math.sqrt(6^2+6^2-2*6*6*math.cos(math.rad(60))))
You also don't need to set a, b, and c - you could just use zs.param directly. If you don't want to do that, it might benefit from using local variables.
EDIT: Misread the example in the post above - checking it, that one works too. |
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Fri Oct 05, 2007 4:07 am |
ahhh.. I didn't realize that function assumed radians.. I guess that's what I get for not doing a complete lookup of the spec.
Thanks Fang, got it working now. |
|
_________________ Asati di tempari! |
|
|
|
|
|