1

I have an user drawn UIBezierPath and I want to know if it intersects itself. Can anyone point me in a good direction for detecting this?

Thanks!

Groot
  • 13,943
  • 6
  • 61
  • 72
  • 2
    Here is a good direction.. http://stackoverflow.com/questions/4039229/checking-if-two-cubic-bezier-curves-intersect – iDev Nov 20 '12 at 23:59
  • Are you not simply checking if the UIBezierPath is closed or not by your question? – hd1 Nov 21 '12 at 00:42
  • No, I do not want to check if it is closed. I just want to know if the path intersects itself. Say the user draws something like http://www.mathatube.com/images/pentagon-complex_1_.gif then we have an intersection. – Groot Nov 21 '12 at 10:25

1 Answers1

1

How do you build your path? Is it just an accumulation of straight line segments? If so you could keep a list of those (parallel to your UIBezierPath, that you use for rendering), and then perform line intersection tests. It'll be O(N^2), though, in the naive implementation.

Wade Tregaskis
  • 1,996
  • 11
  • 15