列出一组坐标之间的坐标 [英] List coordinates between a set of coordinates
本文介绍了列出一组坐标之间的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
1:(1,1)
2:(1,3)
In介于:(1,2)
或
1:(1,1)
2:(5,1)
介于:(2,1),( 3,1),(4,1)
它不需要使用对角线。 p>
解决方案
根据您想要如何处理边缘案例,这似乎工作:
def points_between(p1,p2):
xs =范围(p1 [0] + 1,p2 [0])或[p1 [0]]
ys = range(p1 [1] + 1,p2 [1])或[p1 [1]]
返回x [y(x,y)中的[(x,y)]
$ ((1,1),(5,1))
#[(2,1),(3,1),(4,1)]
((5,6),(5,12))
#[(5,7),(5,8),(5,9),(5,10),(5,11) ]
This should be fairly easy, but I'm getting a headache from trying to figure it out. I want to list all the coordinates between two points. Like so:
1: (1,1)
2: (1,3)
In between: (1,2)
Or
1: (1,1)
2: (5,1)
In between: (2,1), (3,1), (4,1)
It does not need to work with diagonals.
解决方案
Depending on how you want to handle the edge cases, this seems to work:
def points_between(p1, p2):
xs = range(p1[0] + 1, p2[0]) or [p1[0]]
ys = range(p1[1] + 1, p2[1]) or [p1[1]]
return [(x,y) for x in xs for y in ys]
print points_between((1,1), (5,1))
# [(2, 1), (3, 1), (4, 1)]
print points_between((5,6), (5,12))
# [(5, 7), (5, 8), (5, 9), (5, 10), (5, 11)]
这篇关于列出一组坐标之间的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文