What is the best data structure for line segment search?

advertisements

I need a datastructure to find all segments falling in a rectangle (in C#, even if it is not the main problem).

For exemple, the segment [(0,0) , (10,10)] must be in the rectangle begining at (5,5) with the size (1,1).

I tried kdtree, but it returns only segment when one of his point is exactly in the rectangle. It doesn't see the segment as a continous line.

What sort of datastructure do I need to do this search efficiently?
I search but didn't find anything for this case, even if it seems very standard!

Problem Dimension : 6000 segments, average 20 line segment are in the rectangle

Sort of duplicate :

  • How to best store lines in a kd-tree
  • Data structure for fast line queries?

For non-point objects (line segment is not a point object) R-tree may be better suited than kd-tree. If you have a small number of line segments (<50), storing them in a vector and always test all of them may be the fastest way.