uber / h3

Hexagonal hierarchical geospatial indexing system

Home Page:https://h3geo.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

double PointDistanceToEdge( Vector3D Point, H3Index Cell );

SkybuckFlying opened this issue · comments

For visualization/ray tracing purposes it would be handy to have a function which can compute the 64-bit floating point distance from a 3d point on the spereoid lieing inside the h3index to any edge of this H3Hexagon or H3Pentagon and return the shortest/closest distance.

Especially if the edges are treated like line segments across a sphereoid/ellipsoid.

The math involved to do it nanometer accurately is quite heavy and could use some math experts to look at that !

One of the best/most accurate methods is:

Problem exploration:
https://arxiv.org/abs/1102.1215

Link to one of the solutions:
https://proj.org/zreferences.html#id25

Especially this one:

[Karney2013]

Karney, C. F. F. Algorithms for geodesics. Journal of Geodesy, 87(1):43–55, 2013. doi:10.1007/s00190-012-0578-z.

I believe these documents may refer to this problem/solution as "cross track distance".

Slight Update:

This may also be of some help, however, this is only for a sphere so it's not super accurate most likely:

https://www.movable-type.co.uk/scripts/latlong-vectors.html

(Maybe some of the code can be re-used as well, who knows, or serve as inspiration, or testing of a more simple/sphere version)

Thanks for marking it as enhancement, I have updated the original posting a little, with an extra link at the bottom, that may also be usefull ! ;)

It could be an interesting idea to make two versions of this function:

  1. PointDistanceToEdgeFast

  2. PointDistanceToEdgeAccurate

So that it can be used on different kind of systems, slow/weak versus fast/powerfull systems.

This problem is solveable with Geodesic C++ library which also uses NVectors...

  1. https://github.com/sslnjz/geodesy
  2. https://www.ffi.no/en/research/n-vector/