General Question

gorillapaws's avatar

Any programmers willing to help me solve a triangle?

Asked by gorillapaws (30808points) January 20th, 2015

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.

Observing members: 0 Composing members: 0

4 Answers

Mariah's avatar

Are you sure whether your language is using degrees vs. radians for the angle?

johnpowell's avatar

Objective C uses radians. I would assume that Swift uses the same.

gorillapaws's avatar

Thanks guys… I’m an idiot.

Mariah's avatar

Happens to the best of us!

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther