这是代码:
Initialize event queue EQ = all segment endpoints;
Sort EQ by increasing x and y;
Initialize sweep line SL to be empty;
Initialize output intersection list IL to be empty;
While (EQ is nonempty) {
Let E = the next event from EQ;
If (E is a left endpoint) {
Let segE = E's segment;
Add segE to SL;
Let segA = the segment Above segE in SL;
Let segB = the segment Below segE in SL;
If (I = Intersect( segE with segA) exists)
Insert I into EQ;
If (I = Intersect( segE with segB) exists)
Insert I into EQ;
}
Else If (E is a right endpoint) {
Let segE = E's segment;
Let segA = the segment Above segE in SL;
Let segB = the segment Below segE in SL;
Delete segE from SL;
If (I = Intersect( segA with segB) exists)
If (I is not in EQ already)
Insert I into EQ;
}
Else { // E is an intersection event
Add E’s intersect point to the output list IL;
Let segE1 above segE2 be E's intersecting segments in SL;
Swap their positions so that segE2 is now above segE1;
Let segA = the segment above segE2 in SL;
Let segB = the segment below segE1 in SL;
If (I = Intersect(segE2 with segA) exists)
If (I is not in EQ already)
Insert I into EQ;
If (I = Intersect(segE1 with segB) exists)
If (I is not in EQ already)
Insert I into EQ;
}
remove E from EQ;
}
return IL;
}
我在左端点案例中有几个问题 如果a或b不存在怎么办?如果存在并且不存在,我们应该检查第二个是否存在?
在第一次迭代中,SL大多是空的,因此开始时的大多数点都会被删除而不被使用有什么意义呢?
答案 0 :(得分:0)
如果a
和b
不存在,那么当然不可能与它们相交。如果只存在一个,则只能检查那个交叉点。
我不确定你在没有被使用的情况下被删除的意思是什么"。事件队列中的所有事件都很重要,要么是因为它们即将到来的交叉点,要么是因为它们通过使扫描线保持最新来设置潜在的即将到来的交叉点。
最后,它是Bentley-Ottmann,而不是Bentley-Ottoman。