@thk686 if you are interested in a pure Julia solution, I recommend checking the GeoStats.jl stack instead, particularly the Meshes.jl submodule.
You can create an hexagon given a list of vertices in counter-clockwise orientation:
julia> using Meshes
julia> points = [(cos(θ),sin(θ)) for θ in range(0, 2π-π/3, length=6)]
6-element Vector{Tuple{Float64, Float64}}:
(1.0, 0.0)
(0.4999999999999999, 0.8660254037844387)
(-0.5000000000000002, 0.8660254037844386)
(-1.0, 1.2246467991473532e-16)
(-0.4999999999999996, -0.8660254037844388)
(0.5000000000000001, -0.8660254037844386)
julia> hexagon = Hexagon(points)
Hexagon{2,Float64}
└─Point(1.0, 0.0)
└─Point(0.4999999999999999, 0.8660254037844387)
└─Point(-0.5000000000000002, 0.8660254037844386)
└─Point(-1.0, 1.2246467991473532e-16)
└─Point(-0.4999999999999996, -0.8660254037844388)
└─Point(0.5000000000000001, -0.8660254037844386)
and can visualize for debugging purposes:
using MeshViz
import GLMakie as Mke
viz(hexagon)
If you are interested in finding out which hexagon is closest to a given point, you can place the hexagons inside a Collection
, which is a “domain” in our jargon:
gset = Collection([hexagon1, hexagon2, ...])
Then use the KNearestSearch method to query points. Keep in mind that we are actively working on adding new methods, geometries and domain types. Contributions are very welcome.