My algorithm produces a list of (usually) several thousand line segments (all 2D) which I need to join up into large polylines. These resulting polylines might be closed or open, but they are never self-intersecting. The line segments are not directed, i.e. it might be needed to flip a line segment before it can be joined to its neighbour.
What would be an extremely fast way of finding these polylines? I have to do this in real-time, so anything that takes longer than -say- 10ms is not a solution.
I'm doing this in C#, but I'm looking for ideas, not source.
Klee's Algorithm (Length Of Union Of Segments of a line) Count maximum points on same line. Minimum lines to cover all points. Represent a given set of points by the best possible straight line. Program to find line passing through 2 Points.
Two given line segments are said to be intersecting lines when they have a point of intersection. A point of intersection is referred to the point where two or more line segments meet. These lines are not parallel to each other and hence intersect when drawn forward.
Naive Algorithm A naive solution to solve this problem is to check every pair of lines and check if the pair intersects or not. We can check two line segments in O(1) time. Therefore, this approach takes O(n2).
If the endpoints match exactly then you can just store each object twice in a hash, once by each endpoint. Then, for each object, look up both its end points. You will get any other objects that need to be joined.
If the endpoints have any kind of imprecision, then you will need a spatial index, and probably one that uses an R-tree. You can get a similar effect by just making a 2d hash grid. The hash grid contains buckets of nearby endpoints. You will need to check neighboring cells.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With