Skip to content

Deprecate Mesh.from_grid in favor of Mesh.from_lattice - #170

Open
janbridley wants to merge 6 commits into
mainfrom
admin/deprecate-from_grid
Open

janbridley wants to merge 6 commits into
mainfrom
admin/deprecate-from_grid

Conversation

@janbridley

@janbridley janbridley commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

Mesh.from_grid now raises a DeprecationWarning, in favor of the Mesh.from_lattice constructor. I also slightly changed the parameterization of the mesh generation, which anchors the mesh at [1,0,0,0] without significantly changing the uniformity. As far as I know this is novel, although the finding it small and fairly unimportant as one could always just rotate all the outputs from the original mesh to the desired alignment.

def _quaternion_fibonacci_lattice(n):
    """Generate a near-uniform grid of `n` quaternions.

    This is equivalent to a Fibonacci lattice on the 3-sphere. See
    `this paper <https://ieeexplore.ieee.org/document/9878746>`_ for a derivation.
    """
    psi = 1.533751168755204288118041413  # Solution to ψ**4 = ψ + 4
-   s = np.arange(n) + 1 / 2
+   s = np.arange(n, dtype=float)
+   s[1:] += psi / 2
    t = s / n
    d = 2 * np.pi * s
    r0, r1 = (np.sqrt(t), np.sqrt(1 - t))
    α, β = (d / np.sqrt(2), d / psi)

    # Allocate as rows and then transpose, rather than stacking columns
    result = np.empty((4, n))
-   result[...] = r0 * np.sin(α), r0 * np.cos(α), r1 * np.sin(β), r1 * np.cos(β)
+   result[...] = r1 * np.cos(β), r1 * np.sin(β), r0 * np.cos(α), r0 * np.sin(α)
    return result.T

Motivation and Context

In #33 , I added a quaternion fibonacci lattice which I interpreted as being slightly worse than the existing from grid. However, on further review, the fibonacci grid is actually better for the most important metric: max distance. While the average behavior of the pseudo-Tames solutions is better, the worst-case behavior is far worse, as you end up with small holes in the mesh. As a result of this strain, you also end up with some wasted points that are very near one another.

mesh_quality

Looking forward, from_lattice naturally generalizes to other rotation groups (higher dimensions, other metric spaces, 2d, etc.). from_mesh requires a different signature in each dimension even if it performed well.

How Has This Been Tested?

Existing tests pass, and I've added a test to validate the warning. Note that some tests fail if the input mesh does not include the identity quat, so in an ideal world we would bump up the test orientation count and manually exclude the "known" ideal case.

Checklist:

@janbridley
janbridley requested a review from DomFijan November 3, 2026 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant