拉斐尔的相交路径
我试图找出拉斐尔的两条路径是否相交。我尝试过 getBBox() 但它返回路径本身周围的框的坐标。有没有更简单的方法来实现这一目标?
I am trying to found out if two paths are intersected in Raphael. I have tried getBBox() but that returns the coordinates of a box around the path itself. Is there an easier way to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
之前的答案可能适用于拉斐尔的早期版本。 API 现在包含一个 pathIntersection 方法,该方法返回相交点数组。您可以简单地检查返回值的长度。
The previous answers may have been for an earlier version of Raphael. The API now includes a pathIntersection method which returns an array of intersecting points. You can simply check the length of the return value.
暴力破解方法。获取两条路径的所有点,看看两个点是否相同。
我给你做了这个,但也许你应该想出一个更好的比较解决方案。根据您的路径有多长,这可能很重。
Bruteforce method. Get all the points for the two path and see if two points are the same.
I made you this but maybe you should come up with a better comparing solution. Depending on how long your paths are, this can be heavy.
我想你需要自己实现一些东西,因为 Raphael 似乎没有提供这种功能。这是一个可能有帮助的圆交叉示例。 这里有更具体的内容。
在运行实际算法之前,您可能需要检查边界框是否相交。如果存在,请检查实际路径。
I guess you need to implement something yourself as it seems Raphael doesn't provide this sort of functionality. Here's a circle intersection example that might help. Here's something more specific.
Before running your actual algo you probably want to check if the bounding boxes intersect. If they do, check actual paths.
使用这个可爱的交叉库。有了它,你可以做这样的事情:
我的示例中的
inter
对象包含其他好东西。Use this lovely intersection library. With that you can do stuff like this:
The
inter
object in my example contains other good stuff to.