Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a brief description of the intersection algorithm presented in <strong>DuduAlul</strong>'s link.</p> <p>The solution requires the usage of a search tree capable of performing range queries. A range query asks for all items with values between K1 and K2, and it should be an O(R+log N) operation, where N is the total number of tree items, and R is the number of results.</p> <p>The algorithm uses the sweep approach:</p> <p>1) Sort all left and right rectangle edges, according to their X value, into list L.</p> <p>2) Create a new empty range search tree T, for Y ordering of rectangle tops/bottoms</p> <p>3) Create a new empty result set RS of unique rectangle pairs</p> <p>4) Traverse L in ascending order. For all V in L:</p> <p>&nbsp;&nbsp;&nbsp;If V.isRightEdge() </p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T.remove(V.rectangle.top)</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T.remove(V.rectangle.bottom)</p> <p>&nbsp;&nbsp;&nbsp;else</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For all U in T.getRange(V.rectangle.top, V.rectangle.bottom) </p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RS.add(&lt;V.rectangle, U.rectangle>)</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T.add(V.rectangle.top) </p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T.add(V.rectangle.bottom) </p> <p>5) return RS</p> <hr> <p>The time complexity is O(R + N log N) where R is the actual number of intersections.</p> <p><strong>-- EDIT --</strong></p> <p>I just figured out that the solution is not fully correct - the intersection test in tree T misses some cases. The tree should maintain Y intervals rather than Y values, and it should ideally be an <a href="http://en.wikipedia.org/wiki/Interval_tree" rel="nofollow noreferrer">Interval Tree</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload