# Line Segment Intersection - Map Overlay 計算幾何 Min-Te Sun, Ph.D Two of Classical Computational Geometry Problems --- 1. Line Segment Intersection -> 找rivers and road相交的地方 2. Computing the Overlay of Two Subdivisions Line Segment Intersection * Problem statement: -> Given a set S of n closed segments in the plane, report all intersection points among the segments in S * Time Complexity -> Ω (n^2) ## Output-Sensitive Algorithm * 在Output較小時,可以省掉一些時間 * 避免測試所有點 for intersection * 若x-intervals 沒有overlap,則不可能會相交 * 若y-intervals 沒有overlap,則不可能會相交 * 以上方法稱 **plane sweep algorithm** => 將Segments分為 **active Segments** 和 **inactive Segments** ![1](https://hackmd.io/_uploads/SJ-9fyIcR.jpg) * Observation:intersection 會發生在鄰居線段 * Event Points:End points of segments * 𝓵為 **sweep line** * “Active” Line Segments:測試neighboring segments有沒有相交 ### Algorithm --- ![2](https://hackmd.io/_uploads/ByqxIkLqA.jpg) ### HandleEventPoint( p ) --- ![3](https://hackmd.io/_uploads/rJgYPyI5R.jpg) * 1、2、3為定義甚麼是U( p )、L( p )、C( p ) * **U( p ):upper end point 的集合** * **L( p ):lower end point 的集合** * **C( p ):這個集合會經過p,但p不在端點** ### FindNewEvent (S𝓵,Sr,p) ![5](https://hackmd.io/_uploads/B1_HP4Uq0.jpg) --- ### Example ![4](https://hackmd.io/_uploads/S1tbTkUqC.jpg) * p為𝓵上的點,U( p )、L( p )、C( p )分別為: * U( p ):S2 * L( p ):S4、S5 * C( p ):S1、S3 Time Complexity --- * Time Complexity為 O(nlogn + I*logn) -> I 是S集合中intersections的數目 * 每個operation需要O(logn)