in h3_faceijk.c [389:423]
void _geoToHex2d(const LatLng *g, int res, int *face, Vec2d *v) {
// determine the icosahedron face
double sqd;
_geoToClosestFace(g, face, &sqd);
// cos(r) = 1 - 2 * sin^2(r/2) = 1 - 2 * (sqd / 4) = 1 - sqd/2
double r = acos(1 - sqd / 2);
if (r < EPSILON) {
v->x = v->y = 0.0L;
return;
}
// now have face and r, now find CCW theta from CII i-axis
double theta =
_posAngleRads(faceAxesAzRadsCII[*face][0] -
_posAngleRads(_geoAzimuthRads(&faceCenterGeo[*face], g)));
// adjust theta for Class III (odd resolutions)
if (isResolutionClassIII(res))
theta = _posAngleRads(theta - M_AP7_ROT_RADS);
// perform gnomonic scaling of r
r = tan(r);
// scale for current resolution length u
r /= RES0_U_GNOMONIC;
for (int i = 0; i < res; i++) r *= M_SQRT7;
// we now have (r, theta) in hex2d with theta ccw from x-axes
// convert to local x,y
v->x = r * cos(theta);
v->y = r * sin(theta);
}