Quaternion sign in rotation comparisons

Ouverte
#3,975 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
48/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
cpp, python

Piste de recherche

Start by tracing how Scipp compares spatial rotations in sc.identical, ==, sc.allclose, and the functions in sc.testing; the issue provides a Python example showing the inconsistent results for sign-flipped quaternions. Check the existing rotation comparison tests and add coverage for these cases. Done means comparisons treat rotations represented by opposite-sign quaternions consistently with their rotation matrices.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Rotations built from quaternions are invariant under flipping the sign of the quaternion. But Scipp requires them to be exactly the same when comparing them. E.g.:

import numpy as np
import scipp as sc

q1 = np.array([2, 3, -1, -1])
q2 = -q1

r1 = sc.spatial.rotation(value=q1 / np.linalg.norm(q1))
r2 = sc.spatial.rotation(value=q2 / np.linalg.norm(q2))
print(sc.identical(r1, r2))
print(r1 == r2)

one = sc.spatial.linear_transform(value=np.eye(3))
mat1 = r1 * one
mat2 = r2 * one
print(mat1.value)
print(mat2.value)
print(sc.identical(mat1, mat2))

outputs:

False
<scipp.Variable> ()       bool        <no unit>  False
[[-0.33333333  0.66666667 -0.66666667]
 [ 0.93333333  0.33333333 -0.13333333]
 [ 0.13333333 -0.66666667 -0.73333333]]
[[-0.33333333  0.66666667 -0.66666667]
 [ 0.93333333  0.33333333 -0.13333333]
 [ 0.13333333 -0.66666667 -0.73333333]]
True

Here, comparing the rotations directly, we get False. But after converting them to rotation matrices, we get True.

The same happens with sc.allclose and the functions in sc.testing.

I think that Scipp should return True in all comparisons above because, even though the number in the quaternions differ, we interpret them as rotations. So comparisons should be performed in that context. But note that this would mean that r1 == r2 can produce a different result from r1.value == r2.value because the latter uses the rotation context and only compares arrays.

Langage dominant
C++
Étoiles
148
Forks
25
Merge moyen
2 j 13 h
PR mergées (30 j)
16

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de scipp/scipp

Toutes les issues de scipp/scipp

Issues similaires

Plus d'issues C++

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.