I’ve created a “blob” shape by patching cubic Bezier curves together (screenshot below). I’d like to be able to detect the situation where a curve has crossed over either itself or another curve and was wondering if there’s a recommended approach or known algorithm for doing this?
One idea I had was to use a FlatteningPathIterator to decompose the shape into straight line segments and then detect whether a given segment crosses with another one, but I’d be interested in whether there’s a better approach (as this will have quadratic performance). If I do pursue this method are there library functions in Java to detect whether two line segments are overlapping?
Thanks.
No Cross-Over
No Crossover http://www.freeimagehosting.net/uploads/7ad585414d.png
Cross-Over
Crossover http://www.freeimagehosting.net/uploads/823748f8bb.png
I have actually found a working solution which is using built in Java2D functions and is EXTREMELY fast…
Simply create a Path2D out of your curves, then create an area out of your Path2D and invoke the method Area.isSingular();
It works… See this small example.