//! Compute cosine of the angle between two vectors.
double computeCosineOfAngleBetweenVectors( const Eigen::VectorXd& vector0,
const Eigen::VectorXd& vector1 )
{
assert( vector0.size( ) == vector1.size( ) );
// Get the cosine of the angle by dotting the normalized vectors.
double dotProductOfNormalizedVectors = vector0.normalized( ).dot( vector1.normalized( ) );
// Explicitly define the extreme cases, which can give problems with the acos function.
if ( dotProductOfNormalizedVectors >= 1.0 )
{
return 1.0;
}
else if ( dotProductOfNormalizedVectors <= -1.0 )
{
return -1.0;
}
// Determine the actual angle.
else
{
return dotProductOfNormalizedVectors;
}
}
Eigen: 求两个向量的夹角
最新推荐文章于 2023-05-09 17:07:03 发布