Reputation: 475
I'm using Eigen library, v.3.2.1. I'm calculating some normals of some planes. Then I want to normalize them. My problem is that for some normals the calculated norm is not precisely 1.00000, that is:
normalA=(0.0000,0.0000,1165.0521)----->normalA.normalize()=(0.0000,0.0000,1.0000)
normalB=(0.0000,0.0000,1165.0524)----->normalB.normalize()=(0.0000,0.0000,1.0000)
normalC=(0.0000,0.0000,312.17474)----->normalC.normalize()=(0.0000,0.0000,1.0000)
normalD=(0.0000,0.0000,2017.9299)----->normalD.normalize()=(0.0000,0.0000,0.99999994)
My problem is that when I compare normalA with normalD c++ return false and my algorithm fails, i.e if(normalA==normalD).
How could I solve this problem? Are there some function to avoid this simple problem? I'm sorry, but I'm a beginner: teach me!
Upvotes: 1
Views: 8395
Reputation: 21
As already pointed out, the error is caused by floating point arithmetic. This post
[1]: https://stackoverflow.com/questions/15051367/how-to-compare-vectors-approximately-in-eigen
Provides a nice way to cope with your problem.
Best regards
Upvotes: 2