General Question
Any programmers willing to help me solve a triangle?
My trig is a little rusty, and I’m trying to solve a triangle using the side-angle-side method using the law of cosines.
My code is in Swift but is very simple and should be obvious to anyone with any programming experience:
var sideA = 13.128
var sideB = 40.224
var angleC = 91.733
var sideC = sqrt( ((sideA * sideA) + (sideB * sideB)) – (((2 * sideA) * sideB) * cos( angleC )) )
println( sideC )
I’m just using some random variables being generated elsewhere in my code for this example. With these inputs I get sideC = 51.436. If I plug in these same inputs to an online triangle solver I get sideC = 42.688. I get the same answer with other online calculators, so the problem is definitely in my code. I’ve even tried breaking the math into multiple steps to clean it up a bit, and I always get the same, incorrect result. What the heck am I doing wrong? It’s driving me crazy.
Thanks in advance for your help.
4 Answers
Answer this question
This question is in the General Section. Responses must be helpful and on-topic.