python在多边形内随机生成点_随机形状多边形中的点?

利用著名的光线投射算法,可以很容易地确定一个点是否在凸多边形中。在def point_inside_polygon(x, y, poly):

""" Deciding if a point is inside (True, False otherwise) a polygon,

where poly is a list of pairs (x,y) containing the polygon's vertices.

The algorithm is called the 'Ray Casting Method' """

n = len(poly)

inside = False

p1x, p1y = poly[0]

for i in range(n):

p2x, p2y = poly[i % n]

if y > min(p1y, p2y):

if y <= max(p1y, p2y):

if x <= max(p1x, p2x):

if p1y != p2y:

xinters = (y-p1y) * (p2x-p1x) / (p2y-p1y) + p1x

if p1x == p2x or x <= xinters:

inside = not inside

p1x, p1y = p2x, p2y

return inside

但是如果多边形不是完全凸的呢?在

在给定边界点的情况下,如何确定一个点是否是一个随机形状的多边形?在

假设我有一个多边形的边界点

43fa49cc0399814e451bf6d69071d4bd.png

我该怎么做?在

最好用Python编写,但也欢迎任何通用的解决方案。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值