C#中如何判断直线是否与多边形相交?
我有一个与此非常相似的问题:
我正在寻找一种方法(在 C# 中)来判断是否线与任意多边形相交。
我认为 Chris Marasti-Georg 的算法非常有帮助,但缺少最重要的方法,即线与线相交。
有谁知道线相交方法来完成 Chris Marasti-Georg 的代码或有类似的方法吗?
C# 中有内置代码吗?
此方法适用于通过禁区功能增强的 Bing 地图算法。 生成的路径不得穿过禁区(任意多边形)。
I have a question very similar to this:
I am searching for a method (in C#) that tells if a line is intersecting an arbitrary polygon.
I think the algorithm by Chris Marasti-Georg was very helpful, but missing the most important method, i.e. line to line intersection.
Does anyone know of a line intersection method to complete Chris Marasti-Georg's code or have anything similar?
Is there a built-in code for this in C#?
This method is for use with the Bing Maps algorithm enhanced with a forbidden area feature. The resulting path must not pass through the forbidden area (the arbitrary polygon).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
.NET 框架中没有内置用于边缘检测的代码。
下面的代码(移植到 C#)可以满足您的需要(实际算法可以在 Google 群组的 comp.graphics.algorithms 中找到):
There is no builtin code for edge detection built into the .NET framework.
Here's code (ported to C#) that does what you need (the actual algorithm is found at comp.graphics.algorithms on Google groups) :
有点偏离主题,但如果该线是无限,我认为有一个更简单的解决方案:
如果所有点都位于多边形的同一侧,则该线不会穿过多边形线。
在这两个的帮助下:
我得到了这个小宝石:
Slightly off topic, but if the line is infinite I think there's a much simpler solution:
The line does not go through the polygon if all the point lie on the same side of the line.
With help from these two:
I got this little gem:
为了检测 silverlight 地图项目中多边形之间的碰撞,我们使用 Clipper 库:
免费用于商业用途、尺寸小、性能出色且非常易于使用。
Clipper 网页
To detect collisions between polygons in our silverlight map project, we're using clipper library:
Free for commercial use, small size, great performance and very easy to use.
Clipper webpage
这篇文章看起来会有所帮助
http://www.codeproject.com/KB/recipes /2dpolyclip.aspx
此代码是一种二维多边形裁剪算法,可精确确定直线与多边形边界相交的位置。 该代码适用于完全任意形状的凹多边形和凸多边形,并且能够处理任何线方向。
This article looks like it will help
http://www.codeproject.com/KB/recipes/2dpolyclip.aspx
This code is a two-dimensional polygon-clipping algorithm that determines precisely where a line intersects with a polygon border. This code works for both concave and convex polygons of completely arbitrary shape and is able to handle any line orientation.