在二维水平面内
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就是整数点点坐标的集合