【发布时间】:2015-11-20 06:03:28
【问题描述】:
我正在寻找一种算法来找到给定 n 条线段的所有交点。 下面是http://jeffe.cs.illinois.edu/teaching/373/notes/x06-sweepline.pdf的伪代码
输入 S[1 .. n] 是一个行数组 段。 label[i] 是第 i 个最左边端点的标签。
sort the endpoints of S from left to right
create an empty label sequence
for i ← 1 to 2n
line ← label[i]
if isLeftEndPoint[i]
Insert(line)
if Intersect(S[line], S[Successor(line)])
return TRUE
if Intersect(S[line], S[Predecessor(line)])
return TRUE
else
if Intersect(S[Successor(line)], S[Predecessor(line)])
return TRUE
Delete(label[i])
return FALSE
将算法应用于下面设置的线,只检查一个交点。我应该怎么做才能知道其他 2 个交叉点的存在?
- 第[1]行进入
- line[2]进入,line[1]和line[2]的交点被检查。
- line[3]进入,line[2]和line[3]的交点被检查。
- line[4]进入,line[4]和line[1]的交点被检查。找到交叉口 A。
- line[4] 离开,没有任何检查。
- line[1] 离开,没有任何检查。
- line[2] 离开,没有任何检查。
- line[3] 离开,没有任何检查。
【问题讨论】:
-
我认为所描述的算法只检查一组线是否相交。它没有找到交叉点,也没有计算交叉点。
-
@MOehm 我认为你是对的。我错误地认为该算法旨在找到所有的交点。
-
寻找 Bentley-Ottmann 算法
-
您声明要寻找
algorithm to find all the intersection points given n line segments- 假设是二维的。你提出了一个过程,省略了它的名字(AnyIntersections)。5.到8.不会发生,因为 AnyIntersections 以4.终止,返回 TRUE。 你的问题是什么?
标签: algorithm geometry computational-geometry intersection line-segment