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

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

问题描述

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

示例图片:

蓝线:我拥有的线
红线:指示方向
绿线:在指示我想要的旋转方向的曲线上尝试失败.
p0~p3:线的点的x,y坐标.
a:我想要的角度.

我想构建一个函数来给我正确的旋转,使用任何你喜欢的编程语言.

解决方案

也许有一个更优雅的解决方案,但以下有效:

计算 dot product叉积 两个向量.如果叉积为负,则使用点积计算内角(称为alpha"),否则如果叉积为正,则将外角计算为 360°-alpha.

注意叉积取决于操作数的顺序;假设顺序与您的图纸相同,则上述内容有效.

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.

Example image:

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.

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

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