Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
开发者_JS百科 Improve this questioni have 3 Points ((x,y), (x', y'), (x'', y'')) and i want to find the angle in the 3 points i also need to get a point when having the angle and 2 other points (but that shouldn't be a problem)
if it helps - i am working with c#
For a general, non right angle triangle, you need what is known as the Law of Cosines. This allows you to calculate the internal angles at each corner of the triangle given the lengths of each side. You can calculate the length of each side using the Pythagorean equality.
The second part of your question is not clearly specified.
Read the following: http://en.wikipedia.org/wiki/Trigonometric_functions and http://jwbales.us/precal/part6/part6.2.html
cos A = ( b^2 + c^2 - a^2 ) / ( 2 bc )
cos B = ( a^2 + c^2 - b^2 ) / ( 2 ac )
cos C = ( a^2 + b^2 - c^2 ) / ( 2 ab )
then take the arccos on each of the values you get to find the angle.
Study trig, do research, and convert the above equations to code.
Well, the simplest would be to use the scalar product:
double dotprod = (x'' - x)*(x' - x) + (y'' - y)*(y' - y);
double len1 = sqrt((x' - x) * (x' - x) + (y' - y) * (y' - y));
double len2 = sqrt((x'' - x) * (x'' - x) + (y'' - y) * (y'' - y));
double angle = acos(dotprod/(len1*len2));
This should be faster than using the law of cosines.
Edit:
We can omit one sqrt
if doing this way:
double dotprod = (x'' - x)*(x' - x) + (y'' - y)*(y' - y);
double len1squared = (x' - x) * (x' - x) + (y' - y) * (y' - y);
double len2squared = (x'' - x) * (x'' - x) + (y'' - y) * (y'' - y);
double angle = acos(dotprod/sqrt(len1squared*len2squared));
This calculation is basically the same as @David's.
精彩评论