h3 icon indicating copy to clipboard operation
h3 copied to clipboard

Hex Resolution Table error

Open KeithFolkerts opened this issue 5 years ago • 7 comments

The Hex resolution table at https://uber.github.io/h3/#/documentation/core-library/resolution-table has an error. The column heading "Average Hexagon Edge Length (km)" should read "Average Hexagon Radius Length (km)." If you use this length to calculate area, you'll be off by 1/3.

KeithFolkerts avatar Feb 07 '20 00:02 KeithFolkerts

If we were assuming regular hexagons, edge length and radius length would be the same - they're both sides of an equilateral triangle.

H3 hexagons are not regular hexagons, however - they have some distortion due to projection, and are neither perfectly uniform in shape nor perfectly uniform in area. That's why we can only give averages in the table. But AFAIK the assumption that edge length and radius length are equivalent still holds.

nrabinowitz avatar Feb 07 '20 00:02 nrabinowitz

Nick, Thanks for the quick response! The examples that follow are for Resolution 7; when r (inradius or apothem) is 1.220629759 km then the areas is 5.16129km^2—same as in the table. See https://www.calculatorsoup.com/calculators/geometry-plane/polygon.php?n=6&given_data=i&i=1.220629759&units_length=m&sf=6&n_last=6&given_data_last=i&action=solve

However, when the side length (“edge” or a) is 1.220629759 km then the area comes out at 3.877097km^2—which is just 75% of the area shown in the table. See https://www.calculatorsoup.com/calculators/geometry-plane/polygon.php?n=6&given_data=s&s=1.220629759&units_length=m&sf=6&n_last=6&given_data_last=s&action=solve
I think the problem is that the inradius (apothem) is not the same as the edge (side length). The circumradius and the edge are the same. Am I looking at this correctly?

KeithFolkerts avatar Feb 07 '20 00:02 KeithFolkerts

My mistake, I thought you were discussing the circumradius. It's possible the table is incorrectly labeled, as you suggest, though I'm surprised we had a metric for the inradius at all.

I think that table was originally produced mathematically, rather than empirically, and we've had a TODO item for a bit to provide better (or more easily confirmable) stats through empirical sampling.

@isaacbrodsky, do you know more about that column and whether it may be mislabeled?

nrabinowitz avatar Feb 07 '20 17:02 nrabinowitz

@KeithFolkerts You're calculating the area of a planar hexagon, but H3 hexagons are on the sphere and will have greater area due to the spherical excess. I didn't create the average edge length column, so don't know how that was determined. But for the average area column I just divided the surface area of the earth by the number of hexagons at each resolution (accounting for the fact that the 12 pentagons have the same area as 10 hexagons).

sahrk avatar Feb 22 '20 00:02 sahrk

@sahrk Cool we can describe the surface area of the globe to that many significant digits! You're right, I am calculating the area of a planar hexagon, whereas H3 hexes are on the sphere (o,r I suppose, projected on icosahedron faces). There will be sphere-to-icosahedron projection error. Also, the Table of Cell Areas for H3 Resolutions [(https://h3geo.org/#/documentation/core-library/resolution-table)] provides averages that account for the odd pentagon. I can't quote you a precise amount of error associated with these, but I assume it would be a minuscule fraction of 1% as you get to the finer resolution hexes. From the table's stats the Resolution 11 hex has an average area of 0.0021496 sq km (slightly over 1/2 acre). Using this area with this online (planar) hex calculator https://www.calculatorsoup.com/calculators/geometry-plane/polygon.php we get the inradius (apothem) of 0.024910561--to eight significant digits the same as the number in the "Average Hexagon Edge Length" column. Clearly, what the table shows is the inradius not the edge length (or "circumradius"). I'm no mathematician, but I would chalk up this discrepancy to incorrect labeling rather than an error resulting from projections, pentagons, etc.

KeithFolkerts avatar Feb 24 '20 16:02 KeithFolkerts

@KeithFolkerts It has nothing to do with the icosahedron, the projection, accounting for pentagons, etc. Given the edge length of a hexagon, the hexagon will have a different area if it is is on the surface of a sphere than if it is on the plane. You are using a planar hexagon calculator, but H3 hexagons are not planar hexagons. They are spherical polygons, so you would have to use a calculator (or formula) for the area of a spherical hexagon to get the correct area values.

sahrk avatar Feb 24 '20 20:02 sahrk

I was about to add a comment agreeing with @KeithFolkerts. For a planar hexagon with an area of 0.0021496, the inradius is 0.0249 (the figure shown in the table) while the edge length is 0.0288 (bigger by a non-trivial sqrt(4/3)). I can't believe that at the higher resolutions, the earth's curvature is a significant factor.

But then I remembered that the mean of a sqrt is, in general, less than the sqrt of a mean. So the means of both radii will be smaller than we would naively calculate. (I suppose it's possible that this somehow makes the actual mean of the edge length equal to the naive mean of the inradius, but that seems unlikely.) I also learned about distortion vertices which makes the whole thing a little weirder.

It seems to me that an empirical approach to radii would be better, as used for the areas column by @sahrk.

In the mean time, on balance I still think the column should be re-labelled something like "Radius (apothem)".

Finally, I find it unclear in the table whether non-hexagons are included in the averages or not (although it would make little difference at the higher resolutions).

FenderJazz avatar Jul 29 '20 16:07 FenderJazz