You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
intelnal axis value = [[0.0, 2.4492935982947064e-16, 0.0]]
This is very close to [0, 0, 0]. If there was no rounding error, this code would return None in the place where it should return [0, 1, 0].
Why this happens
The matrix corresponding to the rotation of π radians around the y-axis is, without rounding error,
-1 0 0
0 1 0
0 0 -1
So if we calculate axis based on the matrix above, it becomes [0, 0, 0].
The same happens for the rotation around the x-axis, z-axis, or rotation of π radians around any axis. Actually, on my Ubuntu desktop, the code below printed None.
use nalgebra::{Rotation3,Vector3,Unit};constPI:f64 = std::f64::consts::PI;fnmain(){let x = Unit::new_normalize(Vector3::new(1.,2.,1.));let r = Rotation3::from_axis_angle(&x,PI);println!("axis = {:?}", r.axis());}
Another solution is to replace the internal rotation representation in Rotation3 from a 3x3 matrix to a unit quaternion.
The conversion from a unit quaternion to a rotation vector is described in the same section of the paper.
This will improve the overall performance including rotation multiplication, but requires a large amount of modifications.
The text was updated successfully, but these errors were encountered:
IshitaTakeshi
changed the title
Numecirally vulnerable axis calculation in Rotation3
Numerically vulnerable axis calculation in Rotation3
Apr 11, 2024
Abstract
nalgebra::Rotation3::axis
relies on numerically vulnerable calculation.It may return
None
in the place where it should return a non-None value.Issue
In the current implementation of Rotation3, the rotation axis is calculated in the following way.
If I initialize
Rotation3
with a rotation of π radians around the y-axis, the code will look like this.And it actually works.
However, this is very vulnerable, because this behavior relies on the rounding error of the internal matrix representation.
I added the line to print the axis value in the
axis
function.And it said
This is very close to
[0, 0, 0]
. If there was no rounding error, this code would returnNone
in the place where it should return[0, 1, 0]
.Why this happens
The matrix corresponding to the rotation of π radians around the y-axis is, without rounding error,
So if we calculate
axis
based on the matrix above, it becomes[0, 0, 0]
.The same happens for the rotation around the x-axis, z-axis, or rotation of π radians around any axis. Actually, on my Ubuntu desktop, the code below printed
None
.Possible solution
One possible solution is to handle these singular value cases as explained in this paper, section 9.4.1.2 "Logarithm map".
A tutorial on SE(3) transformation parameterizations and on-manifold optimization
Another solution is to replace the internal rotation representation in
Rotation3
from a 3x3 matrix to a unit quaternion.The conversion from a unit quaternion to a rotation vector is described in the same section of the paper.
This will improve the overall performance including rotation multiplication, but requires a large amount of modifications.
The text was updated successfully, but these errors were encountered: