获取两条2d线之间的角度.(关于线条的方向) [英] Get angle between two 2d lines. (With respect to the direction of the lines)

查看:63
本文介绍了获取两条2d线之间的角度.(关于线条的方向)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得两条线之间相对于线方向的角度.线的2个向量的法线点积始终返回两条线之间的最小角度,这不是我想要的.

I want to get the angle between two lines with respect to direction of the line. A normal dot product of the 2 vectors of the lines always returns the lowest angle between the two lines, which is not what I'm looking for.

示例图片:

蓝线:我有的线
红线:方向指示
绿线:尝试弯曲的线尝试失败,该线指示我想要的旋转方向.
p0〜p3:直线点的x,y坐标.
答:我希望获得的角度.

Blue lines: The lines I have
Red lines: indication of the direction
Green lines: failed attempt at a curving line that indicates the direction of the rotation I want.
p0~p3: the x, y coordinates of the points of the lines.
a: The angle I am looking to get.

我想构建一个可以让我正确轮换的函数,使用您喜欢的任何编程语言.

I want to build a function that gives me the correct rotation, use any programming language you prefer.

推荐答案

也许对此有一个更优雅的解决方案,但是可以进行以下工作:

Maybe there is a more elegant solution to this, but the following works:

计算点产品

Compute the dot product and the cross product of the two vectors. If the cross product is negative, compute the inner angle (called "alpha") using the dot product, otherwise if the cross product is positive, compute the outer angle as 360°-alpha.

请注意,叉积取决于操作数的顺序;以上是有效的,前提是要按照您的图纸中的顺序进行.

Note that the cross product depends on the order of operands; the above is valid assuming the order as in your drawing.

这篇关于获取两条2d线之间的角度.(关于线条的方向)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆