artivis / manif

A small C++11 header-only library for Lie theory.
https://artivis.github.io/manif
MIT License
1.51k stars 246 forks source link

cast from float to double #282

Closed minrui-hust closed 8 months ago

minrui-hust commented 11 months ago

when cast SO3 from float to double, a normalized SO3 may be unnormalized even if it is normalized under float precision. This makes code like this impossible:

SO3f f;
// more operation on f
SO3d d;
d = f.cast<double>(); // trigger SO3 un-normalized assertion

work around:

d.coeffs() = f.coeffs().cast<double>()

but this is ugly, and also makes "d" an un-normalized SO3 Any idea to make this more elegant?

artivis commented 10 months ago

Hello,

Thanks for raising this issue, I'll look at it.

Not much more elegant but the following should work,

d = f.coeffs().cast<double>().normalize();

Something else you could do is to use an intermediate quaternion object, something along the lines of,

d.quat( f.quat().cast<double>().normalize() );
minrui-hust commented 10 months ago

Thanks for your reply. Normlizing on coeffs may work for SO3,SO2, but wont work for SE3, SE2。 Maybe we could do normlization in function "cast" (before normlization check in constructor) depending on whether it is cast from higher precision to lower or vice versa

artivis commented 8 months ago

Hi @minrui-hust,

Sorry this took so long but this issue should be fixed now.
Please let me know if you see any further issue.

minrui-hust commented 7 months ago

Thanks a lot,I will try it,it makes great help to me