For illustration purpose, see image below.
Given a point p
and two vectors u
and v
, we can get a linear combination of u
and v
, t = m*u + n*v
, m
and n
are integer, and t should be within the box. Solve this problem is not too difficult. As m
and n
can both be positive and negative. It can be discussed:
- m > 0 and n > 0
- m > 0 and n < 0
- m < 0 and n > 0
- m < 0 and n < 0
Here is the python code for case 1:
m = 0
n = 0
t = m*u+n*v
x = t[0]
y = t[1]
l = []
while (x>0 and x < 1024 and y > 0 and y < 1024):
l.append(t)
m = m + 1
t = m*u+n*v
x = t[0]
y = t[1]
while (x>0 and x < 1024 and y > 0 and y < 1024):
l.append(t)
n = n +1
t = m*u+n*v
x = t[0]
y = t[1]
Using two loops for 4 sets may solve the problem.
Another way is generate too many points and then remove the points outside the box
I think maybe there is other simple and elegant way to do it?