I am trying to find code that would help me simplify a curved path by removing the “loops” in the path. Actually, I am not sure these are properly called loops and not having the right word for this might be hindering my search.
Since StackOverflow won’t let me include illustrations (I’m too new!) just imagine a rollercoaster with sections that loop you upsidedown. I want to remove those loops from the coaster and just leave a path of ups and downs.
I am working in iOS with UIBezierPath paths, but I’d be happy with pointers to examples in pretty much any language, or even just pointers to the right way to describe this problem. An alternative would be techniques to detect paths that intersect themselves so I can just throw the whole path out if a “loop” is present.
Thanks!
This is a non-trivial problem. You can use the GPC (General Polygon Clipping) C library to perform operations like this but it does not directly work with
UIBezierPathand has some licensing restrictions.There is some code on this page that is designed to make GPC work with the Mac
NSBezierPathclass (similar toUIBezierPath) which might get you started in the right direction.