如何将一个边界框分成两个较小的边界框

huangapple go评论123阅读模式
英文:

JS: How to divide a bounding box into two smaller bounding boxes

问题

我们正在使用H3Js库(https://github.com/uber/h3-js)根据边界框(首先转换为多边形,然后使用polygonToCells方法)获取H3单元格。

对于更大的屏幕(4k分辨率),polygonToCells方法返回错误的H3单元格。因此,我想将此边界框分成2或4个部分,这样我就可以获取较小部分的H3单元格,然后将所有的H3单元格合并成一个。

请求的边界框:

15.203087,-109.629878,72.791223,110.448247(纬度/经度格式)

-109.629878,15.203087,110.448247,72.791223(经度/纬度格式)

如何将一个边界框分成两个较小的边界框

英文:

We are using H3Js library (https://github.com/uber/h3-js) to fetch the H3Cells based on boundingBox (First converting into polygon and using polygonToCells method).

For bigger screens (4k resolutions), this method polygonToCells is responding with wrong H3 Cells. So thats why I want to divide this bounding box into 2 or 4 pieces, so I can get the H3 cells for smaller pieces then can merge all of the H3 Cells into one.

Requested Bounding box:

15.203087,-109.629878,72.791223,110.448247 (Lat/lng format)

-109.629878,15.203087,110.448247,72.791223 (Lng/Lat format)

如何将一个边界框分成两个较小的边界框

答案1

得分: 1

这似乎是一个相当简单的几何问题。

你想要找到一个矩形的中点。
你只需要一个算法来找到给定线段的中点。

例如,Mab 的坐标将如下所示:

x = (x1 + x2)/2

y = y1

找到任意线段的中点的通用方法可能是这样的:

const getMidpoint = (a, b) => [(a[0] + b[0])/2, (a[1] + b[1])/2]

a = [2, 4], b = [8, 8]
getMidpoint(a, b) // 这将得到 [6, 6]
getMidpoint([-10, 6], [10, -2]) // 这将得到 [0, 2]

使用这个简单的函数,你可以很容易地计算出原始矩形的中点,如果你想将矩形分成四个部分,你只需要找到两个对立中点(Mab, Mcd 或者 Mbc, Mad)的中点。

希望这样能澄清问题。

英文:

Seems like a pretty simple geometry question.

You want to find the midpoints of a rectangle.
如何将一个边界框分成两个较小的边界框

You just need an algorithm to find the midpoint of a given line segment.

For example, the coordinates of Mab will be as follows:

x = (x1 + x2)/2

y = y1

Generic way to find the midpoint of any line segment will be something like:

const getMidpoint = (a, b) => [(a[0] + b[0])/2, (a[1] + b[1])/2]

a = [2, 4], b = [8, 8]
getMidpoint(a, b) //this will be [6, 6]
getMidpoint([-10, 6], [10, -2]) //this will be [0, 2]

Using this simple function, you can calculate the midpoints of the original rectangle really easily, and if you want to divide the rectangle by four, you just have to find the midpoint of the two opposing midpoints (Mab, Mcd or Mbc, Mad).

Hope this clears things out.

huangapple
  • 本文由 发表于 2023年7月27日 15:14:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76777292.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定