Advertisement

Calc the angles?

Started by February 16, 2002 03:05 AM
2 comments, last by Sim 23 years ago
Hi! How can I calc the angles in a normal triangle (it hasn''t to be a rectanglar), if I have got the lenght of all three sides? thx
a^2 = b^2 + c^2 - 2.b.c.cos A

from which you get the angle A.

Idem for B,C.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
a triangle has 3 points(p1,p2,p3) and
3 edges(e1=p2-p1,e2=p3-p1,e3=p3-p3).
now the edges are vectors.
normalize them! e1.normalize() ...
then e.g. to calc the angle btw. e1 and e2 take the
float dot = dotproduct(e1,e2);
to get the angle in radians -> float angle = acos(dot).
if you want angle in degrees -> angle = (angle * PI) / 180;

hope that helps .
THX ALOT!!!

This topic is closed to new replies.

Advertisement