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.
发布评论
评论(3)
对于一般的非直角三角形,您需要所谓的余弦定律。这允许您在给定每条边的长度的情况下计算三角形每个角的内角。您可以使用毕达哥拉斯等式计算每条边的长度。
你的问题的第二部分没有明确说明。
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.
阅读以下内容:
http://en.wikipedia.org/wiki/Trigonometric_functions 和 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 )
然后对得到的每个值取反余弦以找到角度。
研究三角函数,进行研究,并将上述方程转换为代码。
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.
好吧,最简单的方法是使用标量积:
这应该比使用余弦定律更快。
编辑:
如果这样做的话,我们可以省略一个
sqrt
:这个计算基本上与@David的相同。
Well, the simplest would be to use the scalar product:
This should be faster than using the law of cosines.
Edit:
We can omit one
sqrt
if doing this way:This calculation is basically the same as @David's.