dimforge / dimforge/nalgebra

Behavior of Rotation3::from_matrix(&M) when M is a diagonal matrix

Open
#627 1 comment 5 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
4.8k
Forks
565
PR merge metrics
No merged PRs in 30d

Description

Hello,

While tracking a bug in our code I noticed that `Rotation3::from_matrix` does not behave the way I expected. In particular, for any 3x3 diagonal matrix `M`, `Rotation3::from_matrix(&M)` returns the identity rotation. For example if `M` is
```
[-1, 0, 0,
0, -1, 0,
0, 0, 1],
```
which already is a rotation matrix, then `Rotation3::from_matrix(&M)` returns
```
Rotation {
matrix: Matrix {
data: [
1.0,
0.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
1.0,
],
},
}.
```

After the reading the source code and the paper this function implements, I understand why this is happening, but I was wondering if this is the desired behavior of`from_matrix`. If yes, then I'd expand the documentation of this function a little, in particular I'd mention that for some rotation matrices `M` (like the one above), `Rotation3::from_matrix` might return a rotation which is different than the one described by `M`. Perhaps it's worth mentioning the `Rotation::from_matrix_unchecked` method here too. If this is not the desired behavior then maybe, as suggested by the authors of the paper, randomly perturbating the `rot` matrix to escape the local maximum would do the trick (it could be computationally costly, though).

I think it would be cool if `Rotation3::from_matrix` checked whether the input matrix `M` already is a rotation matrix and, if it is, just return `Rotation::from_matrix_unchecked(M.clone())`.

Thanks!
Kamil

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.