Repository navigation
Closed
Labels
bugSomething isn't working
Description
Hello everyone,
The current implementation of the quat_inv() is as the following:
IsaacLab/source/extensions/omni.isaac.lab/omni/isaac/lab/utils/math.py
Lines 238 to 247 in a4118d7
| 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
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
mpgussert commentedon Oct 17, 2024
good catch! we will probably adopt the more global definitions from omniverse as development continues. thank you!
ozhanozen commentedon Dec 17, 2024
@mpgussert Shall I create a PR to address this until the global definitions are adopted?
Mayankm96 commentedon Mar 25, 2025
From what I see here: https://ch.mathworks.com/help/nav/ref/quaternion.normalize.html
The current implementation seems correct.
ozhanozen commentedon Mar 25, 2025
Hi @Mayankm96,
normalize()is fine, butquat_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.
jtigue-bdai commentedon Jun 27, 2025
A couple of other sources:
https://en.wikipedia.org/wiki/Quaternion
https://graphics.stanford.edu/courses/cs348a-17-winter/Papers/quaternion.pdf
Fixes the implementation of `quat_inv()` (#2797)
Fixes the implementation of `quat_inv()` (isaac-sim#2797)
Fixes the implementation of `quat_inv()` (isaac-sim#2797)
Fixes the implementation of `quat_inv()` (isaac-sim#2797)