计算点之间的角度 [英] Calculating the angle between Points
本文介绍了计算点之间的角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用C ++和opencv
Working with C++ and opencv
我试图计算两点之间的角度...我有一个2D平面,边界框,现在如果框架1中的中心点已经改变其在框架2中的位置,我需要找到这两个点的角度。
I am trying to calculate an angle between two points.....I have a 2D plane with a changing center point of a bounding box, Now if the center point in frame 1 has changed its location in frame 2 i need to find the angle of these two points.
这是我想要做的例子:
有人可以建议一种工作方式。 ...?某些数学解决方案或者可能是C ++函数。
Can someone suggest a way of working this out.......? some kind of mathematical solution or perhaps a C++ function.
推荐答案
使用点击产品:
v1.v2 = v1.x * v2.x + v1.y * v2.y
v1.v2 = |v1| * |v2| * cos(theta)
---------------------------------+
|
+--> theta = acos(v1.v2 / |v1|*|v2|)
示例代码是:
float angleBetween(const Point &v1, const Point &v2)
{
float len1 = sqrt(v1.x * v1.x + v1.y * v1.y);
float len2 = sqrt(v2.x * v2.x + v2.y * v2.y);
float dot = v1.x * v2.x + v1.y * v2.y;
float a = dot / (len1 * len2);
if (a >= 1.0)
return 0.0;
else if (a <= -1.0)
return PI;
else
return acos(a); // 0..PI
}
它计算v1和v2之间的角度如下图
It calculates angle between v1 and v2 as below image
这篇关于计算点之间的角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文