Skip to content

ISEA3H/IVEA3H: getZoneWGS84Vertices winds zones clockwise, opposite of the other grids #21

Description

@ajfriend

When using ISEA3H or IVEA3H, getZoneWGS84Vertices returns a zone's corners in clockwise order (viewed from outside the sphere). The other grids I checked (ISEA7H, IVEA7H, rHEALPix) return counterclockwise. Alternatively, getZoneRefinedWGS84Vertices returns counterclockwise for all five grids.

import dggal as al
al.pydggal_setup(al.Application())


def wise(pts):
    """Compute planar signed area on (lon, lat) to determine orientation.
    positive = counterclockwise.

    Returns CW or CCW accordingly.
    """
    n = len(pts)
    A = sum(
          pts[(i + 1) % n][1] * pts[i][0]
        - pts[(i + 1) % n][0] * pts[i][1]
        for i in range(n)
    )

    if A > 0:
        return 'CCW'
    else:
        return 'CW'


p = al.GeoPoint(42.1, 12.0)

for name in ('ISEA7H', 'IVEA7H', 'rHEALPix', 'ISEA3H', 'IVEA3H'):
    g = getattr(al, name)()
    z = g.getZoneFromWGS84Centroid(8, p)

    corners = [
        (float(v.lon), float(v.lat))
        for v in g.getZoneWGS84Vertices(z)
    ]
    refined = [
        (float(v.lon), float(v.lat))
        for v in g.getZoneRefinedWGS84Vertices(z, 8)
    ]

    print(f'{name:10s} corners: {wise(corners):3s}   refined: {wise(refined)}')

Output:

ISEA7H     corners: CCW   refined: CCW
IVEA7H     corners: CCW   refined: CCW
rHEALPix   corners: CCW   refined: CCW
ISEA3H     corners: CW    refined: CCW
IVEA3H     corners: CW    refined: CCW

Checking exhaustively at levels 0 to 4 (for both 3H grids), every zone comes back CW except two pentagons per level. The level 0 pentagons that come back CCW: AA-0-A and AB-0-A.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions