0

Hello i am trying to do so when line that is drawn as the finger moves on the screen (red line in image below) and when the finger is taken off the screen while the red line has crossed the black line i want an integer variable to increase with 1. Both lines has been drawn using UIBezierPath. But i don't know the most precise way to do this.

edit - The black line comes in from the left side.

zaph
  • 111,848
  • 21
  • 189
  • 228
R4MP3G3
  • 1
  • 2
  • 1
    you posted the wrong image link... – luk2302 Jun 22 '15 at 19:40
  • Sorry that is fixed now – R4MP3G3 Jun 22 '15 at 19:41
  • I am using Objective-C – R4MP3G3 Jun 22 '15 at 19:46
  • Your question is a bit unclear. I assume you know how to solve two linear equations for one unknown, correct? (y=mx+b; y=nx+c; (x,y)=?) You have two lines; you should be able to solve trivially for where they cross; you should be able to trivially tell whether that solution is within the segments. What problem are you having? – Rob Napier Jun 22 '15 at 19:49
  • I am trying to predict where they cross using their X & Y axis, but it is not very precise and to be honest not working very well, so there must be another way to do this. My problem is when the line's X and Y axis meet the requirements (i am using IF statement for this by the way) the line is sometimes not crossed with the black line. – R4MP3G3 Jun 22 '15 at 19:57
  • 1
    That sounds like your code is buggy. You should be able to perfectly predict linear equations. You should provide a Minimal, Complete, and Verifiable example (http://stackoverflow.com/help/mcve). – Rob Napier Jun 22 '15 at 20:19
  • What i use to predict it is something like this: `if (line.begin.y < self.blackBegin.y && line.end.y > self.blackBegin.y && line.end.x < self.blackEnd.x && line.end.x > self.blackBegin.x)` and so on and so on. – R4MP3G3 Jun 22 '15 at 20:32
  • I closed this question as a duplicate because, based on R4MP3G3's last comment, it seems clear he doesn't know the formulas he needs in order to correctly detect when his two line segments intersect. The answers to the linked question provide many ways to find the point of intersection, if there is one, and to report if there isn't one. There's even an answer that uses `CGPoint`. – rob mayoff Jun 22 '15 at 21:20

0 Answers0