取一个正方形,把它分成N个大小相等的小正方形,return它们的中心坐标

Take a square and divide it into N equally sized smaller squares, and return the coordinates of their centres

假设我有一个尺寸为 100 x 100 的正方形。

如果我说 N=4,返回的中心将是 (25,25) (25,75) (75,25) (75,75)

我该如何着手创建算法来解决这个问题?谢谢

假设 N 是一个平方数,这是一种方法:

import math
nd = 100.
N = 4
n = int(math.sqrt(N))
d = nd / n
c = [i*d+d/2 for i in range(n)]
[[(x,y) for x in c] for y in c]

=== Output: ===
[[(25, 25), (75, 25)], [(25, 75), (75, 75)]]

d是每个方格的边长,要平铺的大方格的每边有n;它们的中心偏离边缘 d/2.