开发者

Compute the angle of a triangle when 3 points are given [closed]

Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 11 years ago.

开发者_JS百科 Improve this question

i 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜