Skip to content

[Bug Report] Potential implementation error in quat_inv() #1263

Closed

Description

@ozhanozen

Hello everyone,

The current implementation of the quat_inv() is as the following:

def quat_inv(q: torch.Tensor) -> torch.Tensor:
"""Compute the inverse of a quaternion.
Args:
q: The quaternion orientation in (w, x, y, z). Shape is (N, 4).
Returns:
The inverse quaternion in (w, x, y, z). Shape is (N, 4).
"""
return normalize(quat_conjugate(q))

where normalize() is:
def normalize(x: torch.Tensor, eps: float = 1e-9) -> torch.Tensor:
"""Normalizes a given input tensor to unit length.
Args:
x: Input tensor of shape (N, dims).
eps: A small value to avoid division by zero. Defaults to 1e-9.
Returns:
Normalized tensor of shape (N, dims).
"""
return x / x.norm(p=2, dim=-1).clamp(min=eps, max=None).unsqueeze(-1)

I believe the correct quaternion inverse should include a division with the norm-squared, not the norm. If the input quaternion is not a unit quaternion, the current implementation would give a wrong result. If it is assumed to be a unit quaternion, then we could simply return quat_conjugate(q) without normalizing it again.

I suggest we change the implementation to something like:

def quat_inv(q: torch.Tensor, eps: float = 1e-9) -> torch.Tensor:
    """Computes the inverse of a quaternion.

    Args:
        q (torch.Tensor): The quaternion orientation in (w, x, y, z). Shape is (N, 4).
        eps (float): A small value to avoid division by zero. Defaults to 1e-9.

    Returns:
        torch.Tensor: Inverse quaternion in (w, x, y, z). Shape is (N, 4).
    """
    return quat_conjugate(q) / q.pow(2).sum(dim=-1, keepdim=True).clamp(min=eps)

Checklist

  • I have checked that there is no similar issue in the repo (required)
  • I have checked that the issue is not in running Isaac Sim itself and is related to the repo

Activity

  1. added
    dev team
    bug
    on Oct 17, 2024
  2. mpgussert commented on Oct 17, 2024

    @mpgussert
    Contributor

    good catch! we will probably adopt the more global definitions from omniverse as development continues. thank you!

  3. removed
    dev team
    on Oct 18, 2024
  4. ozhanozen commented on Dec 17, 2024

    @ozhanozen
    ContributorAuthor

    @mpgussert Shall I create a PR to address this until the global definitions are adopted?

  5. Mayankm96 commented on Mar 25, 2025

    @Mayankm96
    Contributor
  6. ozhanozen commented on Mar 25, 2025

    @ozhanozen
    ContributorAuthor

    Hi @Mayankm96, normalize() is fine, but quat_inv() is incorrect.

    The quarternion inverse should be as the following (see MathWorks reference):

    q^{-1} = [w, -x, -y, -z] / ( w^2 + x^2 + y^2 + z^2 ),

    whereas the Isaac Lab implementation effectively does:

    q^{-1} = [w, -x, -y, -z] / sqrt( w^2 + x^2 + y^2 + z^2 ),

    placing the denominator inside the square root. That’s why it’s wrong — you need the squared norm in the denominator, not its square root.

  7. added a commit that references this issue on Jun 28, 2025
    3d6f55b
  8. added a commit that references this issue on Jul 30, 2025
    f3a292d
  9. added a commit that references this issue on Jul 1, 2026
    2b4e2b8
  10. added a commit that references this issue on Jul 8, 2026
    eadda62
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions