triangles angles

Can any one tell me what calculation you have to make to calculate scalene triangles angles if you know all the lengths of the sides?

i am trying to make ik system that will suit my needs and i need to calculate the angles at which my bones should be but i need some angles. i looked on internet but i have no idea how to do all of that in script.

3 Answers

3

You have not search real well have you :slight_smile:

The law of cosines is your answer.

Check there for instance.

Note that this is more of a math question than a unity question.

float AngleOfTriangle(float a, float b, float c){
   float cAng = (a*a+b*b- c*c)/(2*a*b);
   float rad = Mathf.Acos(cAng);
   return Mathf.Rad2Deg(rad);
}

In this case, the c angle represents the angle opposite to the last edge provided as parameter.

EDIT: I realized I made one mistake, it was given as a^a+b^b-c^c but it is aa+bb-c*c those are squared not power of itself.
As requested in Js:

function AngleOfTriangle:float(a:float , b:float, c:float){
   var cAng:float = (a*a+b*b- c*c)/(2*a*b);
   var rad:float = Mathf.Acos(cAng);
   return Mathf.Rad2Deg(rad);
}

And it is “Can you PLEASE write this in Javascript?” :slight_smile:

can you write that in javaScript?

–

thanks agian

–

sorry to bother you but i have some errors like: expecting (, found ':'. about 6 of them and does it change anything if im using unity 3.5?

–

What line? you could remove the :float. The version of Unity does not matter. I am a little rusty on Js... so try with : function AngleOfTriangle(a:float , b:float, c:float)

–

thanks a lot!!!
i was stuck on this for 5 hours

Check that I modified since I found a mistake in my answer. Also, remove this as you are not answering but commenting my answer :).

–

function AngleOfTriangle (a:float , b:float, c:float): float{
var cAng:float = (aa+bb-cc)/(2ab);
var rad:float = Mathf.Acos(cAng);
return Mathf.Rad2Deg
rad;
}