Quaternion sign in rotation comparisons

Offen
#3,975 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
48/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
cpp, python

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
C++
Sterne
148
Forks
25
Ø Merge
2 T. 13 Std.
Gemergte PRs (30 T.)
16

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus scipp/scipp

Alle Issues in scipp/scipp

Ähnliche Issues

Weitere Issues zu C++

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.