- Home /
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.
Answer by fafase · Mar 27, 2013 at 02:50 PM
You have not search real well have you :)
The law of cosines is your answer.
Check there for instance.
http://www.mathsisfun.com/algebra/trig-cosine-law.html
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 a*a+b*b-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?" :)
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)
Answer by gsoft9999 · Mar 27, 2013 at 02:56 PM
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 :).
Answer by gsoft9999 · Mar 27, 2013 at 03:37 PM
function AngleOfTriangle (a:float , b:float, c:float): float{
var cAng:float = (a*a+b*b-c*c)/(2*a*b);
var rad:float = Mathf.Acos(cAng);
return Mathf.Rad2Deg*rad;
}
Your answer
Follow this Question
Related Questions
Mathematicle error help 1 Answer
Trigonometry help? 1 Answer
Unity won't show my programatically created Mesh(A Simple Triangle) 2 Answers
Implementing mathf ? 1 Answer
How do I find the inverse cosine ??? 1 Answer