有没有办法通过滑动在屏幕上画线并检查它们是否相互交叉
我们有一种情况,用户将在屏幕上绘制许多线,我们需要找出交叉线并获得交点。
有没有办法在 iPhone 中使用 cocoa-touch 来实现这一点?请指示一个方向,如果可能的话,代码示例对我来说将是 gr8,因为我从过去 2 天开始就陷入了困境。
请帮忙。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,这纯粹是数学。
当用户触摸屏幕(并用手指移动)时,您将获得一些坐标。根据当前触摸位置 (x,y) 和前一个触摸位置,您可以认为是一条线。将每一行存储在数组中。
现在,当发生新的触摸时,检查该新线(当前触摸坐标和先前的触摸坐标)是否与数组中的任何其他线交叉。
我不记得检查这个交叉点的公式是什么,但经过快速搜索,我发现 这个,也许会有所帮助。
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.