Determine if two lines intersect

倖福魔咒の 提交于 2019-12-04 16:50:16

The lines which contain any line segment (e.g. AB and CD) will always intersect (unless they are parallel).

You want to check if the line segments intersect. This is easy to do by finding the point of intersection and checking if it lies on both line segments.

So, using your example, the two lines (on which line segments AB and CD lie on) intersect at P = (15.4434,47.0697). Now, if P lies on AB then the dot product of PA and PB is negative (since the angle between PA and PB is 180° and cos(180°)=-1).

If you compute the dot product of PA and PB, you will get a positive number (thus it does not lie on AB). However, the dot product of PC and PD gives you a negative number (thus it lies on CD).

Thus, you can check if the line segments intersect if the aforementioned dot products (with the point of intersection) are negative.

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