Task description:
- There are many points on Earth that are constantly changing their coordinates, each with its own speed in real time.
- There are no such points at the north and south poles (radius ~100 km (~65 miles)).
- There is a MySQL database containing information about each of these points (like "name", "color", "coordinates").
What I need to achieve:
At any time, find out which of the points are in radius 5 km(~3.1 miles) around a given point.
Technical limitations:
Since there are a lot of points and their speeds are different, I cannot update information about its coordinates changes in the database very often.
What should I do based on technical limitations:
Divide the whole Earth on some segments which represents 10 km(~6.2 miles) diameter circle and update database only in case of the point changed the segment.
I assume it should be the hexagonal grid (with regular hexagons) like on the picture below,
where:
bigR = 10 km
r = bigR/6 = 1.66(6) km
R = 2 * r / sqrt(3) = 1.9245... km
Since I do not need too precise data, I can assume that:
- The Earth is shaped like a perfect sphere.
- Since there are no points at the poles, I suppose that the sphere can be somehow divided only into hexagons (not hexagons + pentagons).
My questions are:
- How to calculate hexagon identifier/coordinate (like [1,1] or [3,4,12] or [hexA] etc) base on latitude/longitude coordinate given in Universal Transverse Mercator (UTM) format (like on Google Map), e.g. [42.43213479011306, 30.43213479011306]?
- Find all 6 hexagons linked with the one found in question 1 (like on the picture above)?
- Or maybe there is another approach to achieve my task?
Preferred language/library - Javascript.
It looks like the solution might look something like this (on Google Map), but with more hexagons:
I saw this approach, where each hexagon devided by 10 smaller hexagons
but it cannot be applicable in my case because the final hexagon in this example has about 1 km across, but I need 2*r ~= 3.32km
And one more time - i do NOT need draw these hexagons, I just need to divide the Earth on hexagon greed (of some another way base on the task description) and at the any of time moment calculate which hexagon "id" represents chosen point and then calculate all 6 hexagons near by just found.
question from:
https://stackoverflow.com/questions/65835080/how-to-divide-the-whole-earth-into-hexagons-grid-with-some-additional-condition 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…