有效地找到一系列线的交叉点

时间:2017-06-21 03:37:09

标签: language-agnostic geometry lines points

我通过determinants找到一系列行的交集。但是,要查找所有交叉点,我每隔一行检查每一行,创建return Binding.DoNothing;个检查。

是否有更有效的方法来检查所有交叉路口?当我试图理清数百或数千行之间的交叉点时,我害怕运行时间。

1 个答案:

答案 0 :(得分:3)

请注明 - 你的意思是无限的线条?

对于线段,有一种有效的Bentley-Ottmann算法。

对于N个无限线,有大约N ^ 2个交点(如果它们中的大多数不是平行的),所以你的方法在复杂意义上是最优的(也许,微观优化是可能的)

编辑,明确的任务说明Bentley-Ottmann看起来像是开销。

Find intersections of lines with clipping window
(for example, using Liang-Barsky algorithm)
Consider only lines that intersect window

Scan top window border from left corner to the right
Insert every line end into the binary search tree 
(and add link to this tree node from the paired end to the map) 


Scan right window border from top corner to the bottom right one
Check whether current line already has another end in the tree/map
If yes
    all lines with ends between positions of the first and 
    the second ends do intersect with it
    Calculate intersections and remove both line ends from tree and map
else
  Insert line end into the list

Continue for bottom and left edge.

初步处理的复杂度O(N)和与窗口矩形和K交点相交的M行的O(K + MlogM)(注意K可能约为N ^ 2) enter image description here

示例:围绕周边行走的树状态

 E               //and map F to E node
 EG              //and map H to G
 EGI     
 EGIK
 EGIK + H
      H has pair point G, so GH intersect IJ and KL
      remove G
 EIK
 EIK + F
      F has pair point E, so EH intersect IJ and KL
      remove E
 IK
 IK + J
      J has pair point I, so IJ intersect KL
      remove I
 K
 K+L  
    remove K
 end (5 intersections detected)
相关问题