使用 OpenGL 或 CoreGraphics 填充 CGPoints 的触摸绘制路径
我有一个 NSArray 组成路径的点。我可以检测到它何时自相交。发生这种情况时,我会尝试填补该路径。
首先我使用 CoreGraphics,现在我使用 openGl 绘制三角形数组。正如您在图片中看到的那样,效果不佳。
如何仅填充圆形区域,同时保留“尾巴”?我正在考虑反向洪水填充,但不认为 CG 有任何 API 函数用于此......
I have a NSArray of points that make up a path. I can detect when it self-intersects. When this happens, I try to fill the path.
First I used CoreGraphics, now I'm using openGl to draw a triangle array. Doesn't work well as you can see in the image.
How do I fill only the circular area while leaving the "tail" alone? I was thinking of a reverse flood fill but don't think CG has any API functions for this...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您不必实际绘制路径,只需近似路径的直径并用近似值画一个圆即可。
下面是一些检测 iPhone 上的圆形手势的代码:
http://www.mobileorchard.com/iphone-circle-gesture-detection/< /a>
Maybe instead of actually drawing the path you can just approximate the diameter of the path and draw a circle with your approximation.
Here is some code to detect a circle gesture on the iPhone:
http://www.mobileorchard.com/iphone-circle-gesture-detection/
将所有点记录在双向链表中。当需要填充时,从头开始遍历列表并找到最接近末尾的点。然后,连线到该点,然后以相反的顺序连线到每个点,直到列表中的第二个点停止。填充将隐式关闭路径,该路径将从您离开的位置(第二个点)跳回到起始点(第一个点)。
这就是我的想法;您可以尝试几种变体,看看哪种效果最好。您可以记录每个节点中最近的前一个节点,但这对于许多节点来说可能会变得昂贵。
Record all of the points in a doubly-linked list. When it comes time to fill, walk the list from the start and find the point that's closest to the end. Then, lineto that point, then lineto each point in reverse order, stopping with the second point in the list. The fill will implicitly close the path, which will jump from where you left off (the second point) back to the start (first) point.
This is just off the top of my head; you can play with a couple of variations on this to see what works best. You might record the closest previous node in each node, but this could get expensive for many nodes.