如何找出如果两个向量之间的角度为外部或内部? [英] How to find out if the angle between two vectors is external or internal?
问题描述
我知道如何找出角2向量之间,但它总是给我内部的角度,但我希望它给我总是逆时针方向的角度,即便是大于180。 我使用的是C ++,但它是不是真的很重要,因为我需要的理论。
I know how to find out angle between 2 vectors, but it always gives me internal angle, but I want it to give me always the angle in anticlockwise direction, even if it is greater then 180. I'm using C++ but it is not really important because I need to get the theory.
这是我现在使用的
This is what I am using now
推荐答案
您正在寻找的 ATAN2(Y,X)
函数(的 http://en.wikipedia.org/wiki/Atan2 )。如果给它一个二维向量的两个分量,它会给你从x轴的矢量的角度,在反时针方向。为了解决您的特定问题的尝试:
You're looking for the atan2(y,x)
function (http://en.wikipedia.org/wiki/Atan2). If you give it the two components of a 2D vector, it will give you the angle of the vector from the x axis, in the counter-clockwise direction. To solve your specific problem try:
atan2(v_y, v_x) - atan2(u_y, u_x)
然后你可以加上或减去360度,如果答案是出你想要的角度范围内的。
Then you can add or subtract 360 degrees if the answer is out of the range of angles you desire.
这篇关于如何找出如果两个向量之间的角度为外部或内部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!