Re: [eigen] Rotations and unit vectors |
[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]
On 07.05.2013 18:45, Dick Lyon wrote:I guess, normalizing every time would be more consistent then. I assume an inverse sqrt is more expensive than a comparison and a branch, but as both need to be done quite often, it could even be cheaper on average.
How about this: compute the norm of the unit vector, and compare it to 1..
If it's not very close, don't fail out, but normalize the vector.
That would again be another flag which changes global behavior.
Or wrap existing functions with new versions that check and correct norms
of unit vectors, so the programmer can use one or the other; or have a mode
flag that controls whether to normalize; you could even have a mode to fail
out, but people who want a strong check.
Maybe a CHECK_UNIT_VECTOR_NORM(vec, tolerance) that would compile to
nothing, or to an assert, or to a re-normalization, depending on mode.
And, especially if you switch from auto-normalization to do-nothing, you can get very subtle bugs (both versions work, but the latter gets more and more inaccurate over time).
I would vote for just asserting accuracy (which will be disabled in NDEBUG mode), possibly with a customizable tolerance. Most importantly, a program which runs fine in debug mode should give the same results in release mode. And a program that fails in debug mode shall be allowed to give undefined results in release mode.
As for asserting or throwing:
It is possible to change eigen_assert to throw instead of assert and so far eigen_assert is the only way Eigen indicates non-recoverable errors (though mostly these are dimension mismatches etc)
Christoph
--
----------------------------------------------
Dipl.-Inf., Dipl.-Math. Christoph Hertzberg
Cartesium 0.049
Universität Bremen
Enrique-Schmidt-Straße 5
28359 Bremen
Tel: +49 (421) 218-64252
----------------------------------------------
Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |