如何计算形成闭合/开放形状的两个方向向量之间的角度?

发布于 2024-10-04 17:36:01 字数 447 浏览 0 评论 0原文

我正在尝试找出正确的三角函数。等式/函数确定以下内容: 两个方向向量(已确定)之间的角度变化(以度为单位),表示两条线段。 这用于形状识别(用户在屏幕上手绘)的上下文中。

所以基本上,

a)如果用户绘制一个(粗糙的)形状,例如圆形、椭圆形或矩形等 - 构成该形状的线条被分解为.. 20 个点(xy 对)。

b) 我有每个线段的 DirectionVector。

c)因此,线段(x0,y0)的开始点将是前一行的结束点(以便形成一个封闭的形状,例如矩形)。

所以,我的问题是,给定上下文(即确定多边形的类型),如何找到两个方向向量之间的角度变化(可作为 x 和 y 的两个浮点值)???< /strong>

我见过很多不同的三角函数。方程,我正在寻求澄清这一点。

提前非常感谢大家!

I am trying to figure out the correct trig. eq./function to determine the following:
The Angle-change (in DEGREES) between two DIRECTION VECTORS(already determined), that represent two line-segment.
This is used in the context of SHAPE RECOGTNITION (hand drawn by user on screen).

SO basically,

a) if the user draws a (rough) shape, such as a circle, or oval, or rectangle etc - the lines that makes up that shape are broken down in to say.. 20 points(x-y pairs).

b) I have the DirectionVector for each of these LINE SEGMENTS.

c) So the BEGINNING of a LINE SEGMENT(x0,y0), will the END points of the previous line(so as to form a closed shape like a rectangle, let's say).

SO, my question is , given the context(i.e. determinign the type of a polygon), how does one find the angle-change between two DIRECTION VECTORS(available as two floating point values for x and y) ???

I have seen so many different trig. equations and I'm seeking clarity on this.

Thanks so much in advance folks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

夜清冷一曲。 2024-10-11 17:36:01

如果 (x1,y1) 是第一个方向向量,(x2,y2) 是第二个方向向量,则它成立:

cos( alpha ) = (x1 * x2 + y1 * y2) / ( sqrt(x1*x1 + y1*y1 ) * sqrt(x2*x2 + y2*y2) )

sqrt 表示平方根。

查找 http://en.wikipedia.org/wiki/Dot_product

特别是“几何表示”部分”。

If (x1,y1) is the first direction vector and (x2,y2) is the second one, it holds:

cos( alpha ) = (x1 * x2 + y1 * y2) / ( sqrt(x1*x1 + y1*y1) * sqrt(x2*x2 + y2*y2) )

sqrt means the square root.

Look up http://en.wikipedia.org/wiki/Dot_product

Especially the section "Geometric Representation".

你的心境我的脸 2024-10-11 17:36:01

您可以尝试atan2:

float angle = atan2(previousY-currentY, previousX-currentY);

而且,正如前面的答案提到的,

两个向量之间的角度= acos(first.dotProduct(second))

You could try atan2:

float angle = atan2(previousY-currentY, previousX-currentY);

but also, as the previous answers mentioned, the

angle between two verctors = acos(first.dotProduct(second))

℉服软 2024-10-11 17:36:01

我猜你的向量是三个点(x_1,y_1),(x_2,y_2)和(x_3,y_3)。

然后您可以移动这些点,使得 (x_1, y_1) == (0, 0) by

(x_1, y_1) = (x_2, y_2) - (x_1, y_1)
(x_2, y_2) = (x_3, y_3) - (x_1, y_1)

现在您遇到这种情况:

在此处输入图像描述

将此三角形视为两个直角三角形。第一个直角三角形具有 α 角和 β 的一部分,第二个直角三角形具有 β 的另一部分。

然后你可以应用:

在此处输入图像描述

你可以这样计算 alpha:

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

I guess you have the vector as three points (x_1, y_1), (x_2, y_2) and (x_3, y_3).

Then you can move the points so that (x_1, y_1) == (0, 0) by

(x_1, y_1) = (x_2, y_2) - (x_1, y_1)
(x_2, y_2) = (x_3, y_3) - (x_1, y_1)

Now you have this situation:

enter image description here

Think of this triangle as two right-angled triangles. The first one has the angle alpha and a part of beta, the second right-angled triangle has the other part of beta.

Then you can apply:

enter image description here

You can calculate alpha like this:

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

薄暮涼年 2024-10-11 17:36:01

如果我理解正确,您可以只评估两个向量之间的点积,并采用适当的arccos来检索这些向量之间的角度。

If I understand you correctly, you may just evaluate the dot product between two vectors and take the appropriate arccos to retrieve the angle between these vectors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文