Get angle between two 2d lines. (With respect to the direction of the lines)

自闭症网瘾萝莉.ら 提交于 2021-02-19 05:28:00

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/31630946/get-angle-between-two-2d-lines-with-respect-to-the-direction-of-the-lines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!