我想基于(x, y)
创建一个如下列表:
[[0,0], [0,1], [0,2], [1,0], [1,1], [1,2], [2,0], [2,1], [2,2]]
我的实际出发点是(71, 180)
和
x_distance = 105
y_distance = 111
我预期的输出为(6x5)格式:
[[71,180], [176,180], [281,180], [386,180], [491,180], [596,180],
[71,291], [176,291], [281,291], [386,291], [491,291], [596,291],
[71,402], [176,402], [281,402], [386,402], [491,402], [596,402],
[71,513], [176,513], [281,513], [386,513], [491,513], [596,513],
[71,624], [176,624], [281,624], [386,624], [491,624], [596,624]]
我试过下面的代码:
first_xy_x = 71
first_xy_y = 180
x_distance = 150
y_distance = 111
predict_xy_list = []
tem_predict_xy_list = [ ]
tem_predict_xy_list.append(first_xy_x)
tem_predict_xy_list.append(first_xy_y)
predict_xy_list.append(tem_predict_xy_list)
last_x = first_xy_x
last_y = first_xy_y
for x in range(5):
tem_predict_xy_list = [ ]
last_x = int(last_x) + int(x_distance)
for y in range(5):
tem_predict_xy_list = [ ]
last_y = int(last_y) + int(y_distance)
tem_predict_xy_list.append(last_x)
tem_predict_xy_list.append(last_y)
predict_xy_list.append(tem_predict_xy_list)
输出(predict_xy_list
):
[[71, 180], [176, 291], [176, 402], [176, 513], [176, 624], [176, 735], [281, 846], [281, 957], [281, 1068], [281, 1179], [281, 1290], [386, 1401], [386, 1512], [386, 1623], [386, 1734], [386, 1845], [491, 1956], [491, 2067], [491, 2178], [491, 2289], [491, 2400], [596, 2511], [596, 2622], [596, 2733], [596, 2844], [596, 2955], [701, 3066], [701, 3177], [701, 3288], [701, 3399], [701, 3510]]
我也尝试过以下代码:
first_xy_x = 71
first_xy_y = 180
x_distance = 150
y_distance = 111
predict_xy_list = []
tem_predict_xy_list = [ ]
tem_predict_xy_list.append(first_xy_x)
tem_predict_xy_list.append(first_xy_y)
predict_xy_list.append(tem_predict_xy_list)
last_x = first_xy_x
last_y = first_xy_y
tem_predict_xy_list = [ ]
for y in range(4):
tem_predict_xy_list = [ ]
last_y = int(last_y) + int(y_distance)
tem_predict_xy_list.append(first_xy_x)
tem_predict_xy_list.append(last_y)
predict_xy_list.append(tem_predict_xy_list)
print(predict_xy_list)
print(len(predict_xy_list))
print("= = = = = ")
for x in range(5):
tem_predict_xy_list = [ ]
last_x = int(last_x) + int(x_distance)
last_y = first_xy_y
for y in range(5):
tem_predict_xy_list = [ ]
last_y = int(last_y) + int(y_distance)
tem_predict_xy_list.append(last_x)
tem_predict_xy_list.append(last_y)
predict_xy_list.append(tem_predict_xy_list)
print(predict_xy_list)
print(len(predict_xy_list))
输出接近,但y最大值为624,而不是预期的735:
[[71, 180], [71, 291], [71, 402], [71, 513], [71, 624], [221, 291], [221, 402], [221, 513], [221, 624], [221, 735], [371, 291], [371, 402], [371, 513], [371, 624], [371, 735], [521, 291], [521, 402], [521, 513], [521, 624], [521, 735], [671, 291], [671, 402], [671, 513], [671, 624], [671, 735], [821, 291], [821, 402], [821, 513], [821, 624], [821, 735]]
2条答案
按热度按时间kxe2p93d1#
您可以使用
range
选项的全部范围:结果:
kr98yfug2#
您已接近!!