Question

We have a situation in which user will be drawing many lines on the screen and we need to find out the crossing lines and get intersection point.

Is there any way to achieve this in iPhone using cocoa-touch ? Please show a direction and if possible code sample would be gr8 for me as I am stuck for this since last 2 days.

Please help.

Was it helpful?

Solution

As I see it, this is purely mathematics.

When the user touches the screen (and moving around with his finger) you will get some coordinates. Based on the current touch place (x,y) and the previous one, you can consider to be a line. Store each line inside an array.

Now when a new touch takes place, check whether this new line (current touch coordinates and previous ones) cross any other line from your array.

I don't remember what is the formula to check this intersection, but after a quick search, I found this, maybe will help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top