uber / uber/h3

API for UBER H3 to (OpenGL) verteces, triangles, normals.

Open
#694 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
6.5k
Forks
627
Avg merge
3d 21h
Merged PRs (30d)
6

Description

It would be helpfull if there was a UBER H3 api which would return arrays containing enough information to visualize the UBER H3 world via for example OpenGL.

One of these APIs could look like:

H3Error getTriangularWorld( int Resolution, VectorStruct *VectorArray, Triangle *TriangleArray, Vector *NormalArray );

The purposes of this API would be to connect (lines) triangles between all hexagon centers. The initial idea was to connect lines, but lines don't visualize well in OpenGL, no backface culling for lines. So a better idea is to visualize the lines by drawing triangles instead, computing normals for triangles is possible and by setting them when the 3 vectors are added to OpenGL for the triangle, OpenGL will know how to backface cull these triangles, which is handy to not show the back of the earth/world.

Where VectorArray is a dynamic array of
VectorStruct
{
float x,y,z;
};

Where TriangleArray is a dynamic array of
TriangleStruct
{
int64 vi1, vi2, vi3; // vector index.
}

Where NormalArray is a dynamic array of
VectorStruct

VectorArray should be filled with all coordinates of the centers of all hexagons at the specified resolution.

TriangleArray should be filled with all indices of the triangles which describe the hexagon. The order of the indices should be such that when computing the plane normal (using formula below) it's pointing outwards.

NormalVector := CalcPlaneNormal
(
VectorArray[ TriangleArray[ Index ].vi1 ], VectorArray[ TriangleArray[ Index ].vi2 ], VectorArray[ TriangleArray[ Index ].vi3 ]
);

TAffineVector = VectorStruct;

function CalcPlaneNormal(const p1, p2, p3: TAffineVector): TAffineVector;
var
V1, V2: TAffineVector;
begin
VectorSubtract(p2, p1, V1);
VectorSubtract(p3, p1, V2);
VectorCrossProduct(V1, V2, result);
NormalizeVector(result);
end;

procedure VectorSubtract(const V1, V2: TAffineVector;
var result: TAffineVector);
begin
result.X := V1.X - V2.X;
result.Y := V1.Y - V2.Y;
result.Z := V1.Z - V2.Z;
end;

procedure VectorCrossProduct(const V1, V2: TAffineVector;
var vr: TAffineVector); overload;
begin
vr.V[X] := V1.V[Y] * V2.V[Z] - V1.V[Z] * V2.V[Y];
vr.V[Y] := V1.V[Z] * V2.V[X] - V1.V[X] * V2.V[Z];
vr.V[Z] := V1.V[X] * V2.V[Y] - V1.V[Y] * V2.V[X];
end;

procedure NormalizeVector(var V: TAffineVector);
var
invLen: Single;
vn: Single;
begin
vn := VectorNorm(V);
if vn > 0 then
begin
invLen := RSqrt(vn);
V.X := V.X * invLen;
V.Y := V.Y * invLen;
V.Z := V.Z * invLen;
end;
end;

function VectorNorm(const V: TAffineVector): Single;
begin
result := V.X * V.X + V.Y * V.Y + V.Z * V.Z;
end;

function RSqrt(V: Single): Single;
begin
result := 1 / Sqrt(V);
end;

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files or tests are named. Start by locating the existing public H3 API and the entry points that produce hexagon centers and coordinates, then assess how a triangular visualization API would fit. Done would require a maintainer-approved API design, documented array ownership and indexing, outward-facing triangle ordering, and coverage for the generated geometry and normals.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
api, computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.