线interesection横向横向、interesection

2023-09-11 05:29:57 作者:笑靥如花

我有几个线段。而线是随机的。我要检查是否有任何两个线之间任何交集。线可以连接或不连接。什么是对这个问题最好的算法。

I have several line segments . And lines are random. I have to check if there any intersection between any two line. Lines may be connected or not. What would be best algorithm for this problem.

code例子很多AP preciated。

Code Example is much appreciated.

编辑:线段

推荐答案

假设你正在谈论的线段这里(否则,只比较直线的斜率:如果他们有不平等的山坡上,它们相交)。

Assuming you're talking about line segments here (otherwise, simply compare the slopes of the lines: if they have unequal slopes, they intersect).

要了解一个[单一]交汇存在于一组2个或更多的线段,可以使用Shamos - 霍伊算法。

To find out if a [single] intersection exists in a set of 2 or more line segments, you can use the Shamos-Hoey algorithm.

要查找的所有的一组2个或更多的线段,可以使用宾利奥特曼算法。交点

To find all intersections in a set of 2 or more line segments, you can use the Bentley-Ottmann algorithm.

二实施,及其他扫线的算法,有丰富的在互联网上提供。

Implementation of the two, and other "sweep-line" based algorithms, are abundantly available on the internet.