问题描述
我有一个动态创建的多边形和折线.现在,我需要检查它们是否彼此相交.
I have a polygon and polyline created dynamically. Now I need to check whether they both intersect each other or not.
我该如何实现?谷歌搜索没有提供令人满意的结果.
How do I achieve this? Googling hasn't provided any satisfactory results.
谢谢丹尼尔
推荐答案
您需要遍历第一条多边形/折线的每个线段,并检查它是否与第二条多边形/折线的每个线段相交.如果一个相交,则两个几何相交.
You need to iterate over each segment of the first polygon/polyline and check if it intersects each segment of the second polygon/polyline. If one intersects, there the two geometries intersect.
如果您不需要考虑测地线,则可以在此处查看建议的实现:(还有一种Java脚本实现可以满足您的需求: https://github.com/pgkelley4/line-segments-intersect/blob/master/js/line-segments-intersect.js )
If you don't need to take into account geodesic lines, you can take a look at the suggested implementations here: How do you detect where two line segments intersect? (there is also a Javascript implementation that may suit your needs: https://github.com/pgkelley4/line-segments-intersect/blob/master/js/line-segments-intersect.js)
这篇关于使用Google Maps API v3相交多边形和折线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!