Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
396 views
in Technique[技术] by (71.8m points)

javascript - How to divide the whole Earth into hexagons grid (with some additional conditions, see below)?

Task description:

  1. There are many points on Earth that are constantly changing their coordinates, each with its own speed in real time.
  2. There are no such points at the north and south poles (radius ~100 km (~65 miles)).
  3. 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

enter image description here

Since I do not need too precise data, I can assume that:

  1. The Earth is shaped like a perfect sphere.
  2. 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:

  1. 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]?
  2. Find all 6 hexagons linked with the one found in question 1 (like on the picture above)?
  3. 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: enter image description here

I saw this approach, where each hexagon devided by 10 smaller hexagons enter image description here

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...