gpt4 book ai didi

algorithm - 给定点位于多边形内部或外部

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:47:07 24 4
gpt4 key购买 nike

我正在尝试这个问题并找到了解决方案:

在每个点的右边画一条水平线,并延伸到无穷远

1) Count the number of times the line intersects with polygon edges.
2) A point is inside the polygon if either count of intersections is odd or point lies on an edge of polygon. If none of the conditions is true, then point lies outside. polygon

但我认为有一个简单的解决方案:

for(all sides in same order)
find vector product of the 3 points (given point and end points of each side)

if all products are > or < 0 : point lies inside polygon or on boundary<br/>
else outside

我的解决方案不是更好更高效吗?
还有比这更简单的算法吗?

最佳答案

所提出的使用叉积检查的算法仅适用于凸多边形。对于非凸多边形,很容易找到它不起作用的示例。尝试给定多边形中的任意点 cde

关于algorithm - 给定点位于多边形内部或外部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20349482/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com