求三维空间缓冲区域内部的整数点 python

在二维水平面内

from skimage.draw import polygon
from shapely import LineString, buffer
a=[2,1]
b=[5,5]
line = LineString([(a[0], a[1]), (b[0], b[1])])
# buffer设置缓冲区
x, y = buffer(line, 2, cap_style="round").boundary.xy
# x,y是缓冲区边缘连续的点坐标
rr1, cc1 = polygon(x, y)  # 得到矩形中所有正整数点的行和列
plt.plot([a[0],b[0]],[a[1],b[1]])
plt.scatter(x,y,color='r')
plt.scatter(x,y)
plt.show()
# 得到坐标集合
xy=[list(i) for i in zip(rr1,cc1)]

在三维空间中

from skimage.draw import polygon
from shapely import LineString, buffer

a=[2,1,3]
b=[5,5,5]

line = LineString([(a[0], a[1]), (b[0], b[1])])
x, y = buffer(line, 2, cap_style="round").boundary.xy
rr1, cc1 = polygon(x, y)  # 得到举行中所有点的行和列
ax=plt.axes(projection='3d')
ax.scatter(rr1, cc1, np.zeros((len(rr1))))

line = LineString([(a[0], a[2]), (b[0], b[2])])
x, z = buffer(line, 2, cap_style="round").boundary.xy
rr2, cc2 = polygon(x, z)  # 得到举行中所有点的行和列
ax.scatter(rr2, np.zeros((len(rr2))), cc2)

line = LineString([(a[1], a[2]), (b[1], b[2])])
y, z = buffer(line, 2, cap_style="round").boundary.xy
rr3, cc3 = polygon(y, z)  # 得到举行中所有点的行和列
ax.scatter(np.zeros((len(rr3))), rr3, cc3)
xyl = [] # 坐标集合
for i in zip(rr1, cc1):
    for j in zip(rr2, cc2):
        for l in zip(rr3, cc3):
            if i[0] == j[0] and i[1] == l[0] and j[1] == l[1]:
                loc = [i[0], i[1], j[1]]
                xyl.append(loc)
# xyl就是整数点点坐标的集合

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值