forked from jan/opencl_fdtd
Fix triangular lattice code in pgcgen
This commit is contained in:
parent
c754e1c1ad
commit
89e305f78e
19
pcgen.py
19
pcgen.py
@ -30,13 +30,20 @@ def triangular_lattice(dims: List[int],
|
|||||||
k = 1
|
k = 1
|
||||||
|
|
||||||
positions = []
|
positions = []
|
||||||
for j in numpy.arange(dims[1]):
|
ymax = (dims[1] - 1)/2
|
||||||
j_odd = j % 2
|
for j in numpy.linspace(-ymax, ymax, dims[0]):
|
||||||
x_offset = (j_odd * 0.5) - dims[0]/2
|
j_odd = numpy.floor(j) % 2
|
||||||
y_offset = dims[1]/2
|
|
||||||
xs = numpy.arange(dims[0] - k * j_odd) + x_offset
|
x_offset = j_odd * 0.5
|
||||||
ys = numpy.full_like(xs, j * numpy.sqrt(3)/2 + y_offset)
|
y_offset = j * numpy.sqrt(3)/2
|
||||||
|
|
||||||
|
num_x = dims[0] - k * j_odd
|
||||||
|
xmax = (dims[0] - 1)/2
|
||||||
|
xs = numpy.linspace(-xmax, xmax - k * j_odd, num_x) + x_offset
|
||||||
|
ys = numpy.full_like(xs, y_offset)
|
||||||
|
|
||||||
positions += [numpy.vstack((xs, ys)).T]
|
positions += [numpy.vstack((xs, ys)).T]
|
||||||
|
|
||||||
xy = numpy.vstack(tuple(positions))
|
xy = numpy.vstack(tuple(positions))
|
||||||
return xy[xy[:, 0].argsort(), ]
|
return xy[xy[:, 0].argsort(), ]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user