Skip to content

Eigen Dot product of normalized Vector3fs returns numbers outside -1 .. 1. Using std::acos on this will generate NaN values. #1033

Closed
@mschoeler

Description

@mschoeler

From pcl/segmentation/include/pcl/segmentation/impl/lccp_segmentation.hpp Lines 434++

const Eigen::Vector3f source_normal = sv_source->normal_.getNormalVector3fMap (). normalized ();
const Eigen::Vector3f target_normal = sv_target->normal_.getNormalVector3fMap (). normalized ();
float dot_normal = source_normal.dot (target_normal);
float normal_angle = std::acos (dot_normal) * 180. / M_PI;

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:

if (dot_normal > 1)
{
  dot_normal = 1;
}
if (dot_normal < -1)
{
  dot_normal = -1;
}

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions