trlog2 loses the quadrant for valid SO(2) and SE(2) rotations
Les mainteneurs répondent en général sous 1 jour
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 72/100
Piste de recherche
Le bogue se trouve dans trlog2 dans spatialmath/base/transforms2d.py, où les deux branches récupèrent l'angle avec atan(sin/cos) et perdent le quadrant. Commence par là et vérifie si atan2 appliqué aux mêmes éléments de sinus et de cosinus corrige les cas à 120° et 180°. Exécute le reproducteur de l'issue, qui compare trlog2, SO2.log, SE2.log et Twist2(SE2).exp aux logarithmes exacts. C'est terminé lorsque les cinq allers-retours réussissent à 120° et 180° et que le contrôle à 30° réussit toujours.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
trlog2 returns logarithms that don't exponentiate to valid 120° and 180° inputs. SO2.log(), SE2.log() and Twist2(SE2(...)).exp() inherit this.
Version: spatialmath-python 1.1.18, 2de780137049040a665225b59d65d95ec93a9e13, Python 3.12.3, SymPy 1.14.0, mpmath 1.3.0, Linux x86_64, NumPy 1.26.4 / SciPy 1.15.3 and NumPy 2.5.4 / SciPy 1.18.1.
In an empty directory, use Python 3.12 and Bash:
git clone https://github.com/rai-opensource/spatialmath-python.git spatialmath-python
git -C spatialmath-python checkout --detach 2de780137049040a665225b59d65d95ec93a9e13
python3.12 -m venv .venv
.venv/bin/python -m pip install -e ./spatialmath-python numpy==1.26.4 scipy==1.15.3 sympy==1.14.0 mpmath==1.3.0
OPENBLAS_NUM_THREADS=1 OMP_NUM_THREADS=1 .venv/bin/python - <<'PY'
"""Exact SO(2)/SE(2) log references, including a common 120-degree pose."""
import numpy as np
import sympy as sp
from scipy.linalg import expm
from spatialmath import SO2, SE2, Twist2
from spatialmath.base import trlog2
def numeric(m):
return np.array(sp.Matrix(m).evalf(60).tolist(), dtype=float)
failures = []
for degrees in (30, 120, 180):
theta = sp.pi * degrees / 180
c, s = sp.cos(theta), sp.sin(theta)
R = sp.Matrix([[c, -s], [s, c]])
T = sp.eye(3)
T[:2, :2], T[:2, 2] = R, sp.Matrix([1, 2])
# exp([v,theta]) translates by V(theta)*v.
V = sp.Matrix([[s, -(1-c)], [1-c, s]]) / theta
v = V.inv() * sp.Matrix([1, 2])
logR = sp.Matrix([[0, -theta], [theta, 0]])
logT = sp.Matrix([[0, -theta, v[0]], [theta, 0, v[1]], [0, 0, 0]])
np.testing.assert_allclose(expm(numeric(logT)), numeric(T), atol=1e-14)
for name, actual, expected in (
('trlog2(SO2)', trlog2(numeric(R)), numeric(logR)),
('SO2.log', SO2(numeric(R)).log(), numeric(logR)),
('trlog2(SE2)', trlog2(numeric(T)), numeric(logT)),
('SE2.log', SE2(numeric(T)).log(), numeric(logT)),
('Twist2(SE2).exp', Twist2(SE2(numeric(T))).exp().A, numeric(T)),
):
error = np.max(np.abs(actual - expected))
print(f'{degrees:3d} deg {name:17s} max error {error:.12g}')
# Any real logarithm branch is acceptable if its exponential is the
# specified input. This also accepts either sign at the half-turn.
target = numeric(R) if name in ('trlog2(SO2)', 'SO2.log') else numeric(T)
recovered = actual if name == 'Twist2(SE2).exp' else expm(actual)
if not np.allclose(recovered, target, atol=1e-12, rtol=0):
failures.append((degrees, name))
print('log rotation =', trlog2(numeric(R), twist=True))
assert not failures, f'Confirmed deviations: {failures}'
PY
The trlog2 contract defines SO(2)/SE(2) matrix logarithms, so exp(log(T)) should recover T. Inputs meet documented forms with default checks enabled and no documented angle bound.
At 120°, trlog2(R, twist=True) returns -pi/3 instead of 2*pi/3, and at 180°, zero. Both angles fail all five round trips. The 30° control passes.
Both branches lose the quadrant through atan(sin/cos). atan2 with the same sine and cosine entries would preserve it.
We tested singleton matrices at 30°, ±120° and 180°, without sequences or robot workflows.
The reproducer is provided under CC0-1.0. Happy to send a PR.
— ChipLab
- Langage dominant
- Python
- Étoiles
- 648
- Forks
- 108
- Merge moyen
- 9 j 19 h
- PR mergées (30 j)
- 9
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de rai-opensource/spatialmath-python
-
documentation
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
rai-opensource/spatialmath-python#235 ·
Les mainteneurs répondent en général sous 1 jour
-
enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
rai-opensource/spatialmath-python#32 · 4 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
enhancement
Difficulté 4/5 3-5 jours Accessibilité débutants 45/100
rai-opensource/spatialmath-python#268 ·
Les mainteneurs répondent en général sous 1 jour
-
expand_dims(None) raises TypeError although None is its documented defaultPeut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 52/100
rai-opensource/spatialmath-python#261 ·
Les mainteneurs répondent en général sous 1 jour
-
documentation enhancement
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 15/100
rai-opensource/spatialmath-python#257 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de rai-opensource/spatialmath-python
Issues similaires
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
ansys/pyansys-common-mcp#213 ·
Les mainteneurs répondent en général sous 3 jours
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
freedomofpress/dangerzone#1594 ·
Les mainteneurs répondent en général sous 3 jours
-
priority:P1 status:in-review type:bug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
randomparity/kdive#3317 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
area:ci
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 66/100
mesonbuild/meson#16281 ·
Les mainteneurs répondent en général sous 1 jour