'Generating list of hexagonal coordinates
I am gonna try to frame this in an understandable way but please let me know if further clarification is necessary. I am trying to create a list of hexagonal coordinates (each pt(x,y) represents a point on the edge of a hexagon) in a list form, where all the points, centers, and edges are split into separate lists. I know the following code is incorrect, like pseudocode but this is what I am trying to do:
import numpy
from itertools import product
ratio = numpy.sqrt(3)/2
N = 120
N_X = int(numpy.sqrt(N)/ratio)
N_Y = N//N_X
sites = list() #creates list of all sites
esites = list() #creates list of edge sites
csites = list() #creates list of center sites
for site in product(range(0,N_X),range(0,N_Y),range(0,1)):
x,y,z = site # initializes the x, y, z components of the site list
for x in site[::2,:,:]: # loops over every other x site, all y and z
x = ratio*x # multiplies every other x by ratio to get hexagon
sites.append(site) # appends to the sites
if site = x[1:2,::2] or x[::2] and y[1::2,::2] or y[::2]: # loops over the positions of the edge sites and appends or if not appends to the center
esites.append(site)
else:
csites.append(site)
Again, I know this code is mere pseudo code so please no negative comments, and yes I have read the past comments on generating hexagonal grids. Any input on how to do something like this would be greatly appreciated. The output I am expecting is a list with size of all the positions, another with all the edges, and one with all the corners.
Note I have tried this with zip and the output format won’t work with my program even by transforming the zip into a list.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
