最近在做一个项目,需要将点云投影至任意平面,尝试了网上pcl的投影代码。利用平面法向量总是不能得到正确的结果,于是采用CGAL实现了一下。
大致原理是:
点云投影到空间中任意平面,实际是点云沿着该点P到目标平面Plane的垂线进行投影。这样问题就变成利用已知点P构造一条垂直于目标平面Plane的直线L,L平行于目标平面的法向量,求直线L 和Plane的交点。
代码如下:
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_2_algorithms.h>
#include <CGAL/Plane_3.h>
#include <CGAL/Polygon_2.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::FT FT;
typedef Kernel::Point_3 myPoint;
typedef Kernel::Plane_3 Plane;
struct edge_pt
{
vector<myPoint> pt;
};
vector<double> Plane_func(edge_pt wall)
{