Greetings,
I need a fast(er) method for detecting all intersections of a line with itself. The line is defined by x,y coordinates that change in time and eventually intersect. This is a numerical model of a river centerline over long time scales, if that helps with the picture. Here's a video of a simulation:
http://www.youtube.com/watch?v=VR0SFmz6JRc
Each time step I have to check for intersections. I am currently using intersections.m from the File Exchange by Douglas Schwartz: see
http://www.mathworks.com/matlabcentral/fileexchange/11837-fast-and-robust-curve-intersections , but it operates on O(n^2) time. I know there are algorithms like the Bentley-Ottmann that operate on O(n*log(n)) time, but I haven't found any implementations in Matlab. I've spent hours now trying to create MEX files from C implementations, but I can't find all the necessary libraries for the algorithms I've found online. I've also tried a java implementation but again, the libraries weren't complete or available.
Obviously I'm avoiding coding this in Matlab myself for a couple reasons. I don't think Matlab is well-suited for sweep-line algorithms (but I'm still trying to wrap my head around them), so I'm wondering if programming in Matlab script will be that much faster. I suppose it depends on n, but also the way its coded could make a huge difference.
I recently increased n from ~1000 to ~4000, and the model runtime has gone from ~4 hours to ~4 days, hence my desire to implement a faster intersection method. The code calls intersections.m three times per time step, so a faster algorithm would be wonderful. intersections.m was the second-longest time hog according to the profiler (much of the time is spent on repmat).
Any suggestions, hints, or help?
Thanks.