开发者

Is there any way to draw lines on screen by swiping and check whether they are crossing each other

开发者 https://www.devze.com 2023-03-12 04:30 出处:网络
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.

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号