-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eigen Dot product of normalized Vector3fs returns numbers outside -1 .. 1. Using std::acos on this will generate NaN values. #1033
Comments
Did you check the content of |
no it does not. Here is an example output I just generated.
|
Switching to doubles should help but I don't think the problem will disappear. |
I think that the reason Victor gave is correct. And I think there is no better way than to do: dot_normal = dot_normal > 1.0 ? 1.0 : (dot_normal < -1.0 ? -1.0 : dot_normal); (Or the same way as you did with |
I also think it is an rounding error. Still I find it strange, that Eigen has no build in protection against this (I also could not find an issue regarding this). Using the acos after a dot product of normalized vectors is a very common operation and yielding 0 or NaN is a very big difference. Maybe it makes sense to include a function which calculates the angle betwee two vectors in PCL? Until we find a better solution I will prepare this fix. |
It would totally make sense. (But maybe there exists one somewhere and we are just not aware of it :))
I see no way how such a protection could be implemented. Dot product routine does not know whether it multiplies normalized vectors or not. Normalization routine has no idea whether its result will be used further for dot product. |
You could for example round the dot product to one digit less than the precision of float. That way you probably could adapt Victor's idea and get exactly 1 instead of 1+. It would not hurt the angle calculation too much. |
From
pcl/segmentation/include/pcl/segmentation/impl/lccp_segmentation.hpp
Lines 434++This leads in some cases to dot_normal > 1 or dot_normal < 1 and to normal_angle being NaN.
This again causes LCCP to treat some connections on perfectly flat surfaces to be concave.
I implemented a quick fix:
but this is not nice, obviously. Does anybody know the cause why Eigen's dot product returns numbers not correctly normalized and how to prevent it?
The text was updated successfully, but these errors were encountered: