【问题标题】:how t use this function "pcl::geometry::squaredDistance" correctly如何正确使用此功能“pcl::geometry::squaredDistance”
【发布时间】:2020-07-17 14:37:06
【问题描述】:

如何获得 PCL 中两点之间的距离? 我知道 PCL 中有一个函数 pcl::geometry::squaredDistance,但是当我调用这个函数时,我得到了这个错误

/usr/include/pcl-1.7/pcl/common/geometry.h: In instantiation of ‘float pcl::geometry::squaredDistance(const PointT&, const PointT&) [with PointT = pcl::PointXYZ]’:
error: no match for ‘operator-’ (operand types are ‘const pcl::PointXYZ’ and ‘const pcl::PointXYZ’)
Eigen::Vector3f diff = p1 -p2;
                          ^

这是显示我如何使用该函数的代码

    pcl::PointXYZ p1(3, 4, 5);

    pcl::PointXYZ p2(0, 0, 0);

    double d = pcl::geometry::squaredDistance(p1, p2);

    std::cout << d << std::endl;

任何帮助将不胜感激。

【问题讨论】:

  • 请努力将错误文本复制到您的问题中。

标签: point-cloud-library point-clouds


【解决方案1】:

这是PCL 1.7 (that was fixed in linked commit) 中的一个错误。

这是一个简单的功能,因此您不必更新到较新版本的 PCL:

返回两点之间的欧式距离

    template <typename PointT> inline float 
    distance (const PointT& p1, const PointT& p2)
    {
      Eigen::Vector3f diff = p1.getVector3fMap () - p2.getVector3fMap ();
      return (diff.norm ());
    }

返回两点之间的平方欧式距离(比真正的欧式距离计算速度更快)

    template<typename PointT> inline float 
    squaredDistance (const PointT& p1, const PointT& p2)
    {
      Eigen::Vector3f diff = p1.getVector3fMap () - p2.getVector3fMap ();
      return (diff.squaredNorm ());
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-30
    • 1970-01-01
    • 2021-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-28
    • 1970-01-01
    相关资源
    最近更新 更多