def hexagonal_uniform(N,as_complex=False):
'returns uniformly distributed points of shape=(2,N) within a hexagon whose minimum radius is 1.0'
phi = 2*pi/6 *.5
S = np.array( [[1,1],np.tan([phi,-phi])] ) # vectors to vertices of next hexagon ( centered at (2,0) )a
# uniformly sample the parallelogram defined by the columns of S
v = np.matmul(S,np.random.uniform(0,1,(2,N)))
v[0] = 1 - abs(v[0]-1) # fold back to make a triangle
c = (v[0] + 1j*v[1]) * np.exp( 2j*pi/6*np.floor( np.random.uniform(0,6,N) ) ) # rotate to a random sextant
if as_complex:
return c
else:
return np.array( (c.real,c.imag) )
评论列表
文章目录