#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
Kernel::Point_3 compute_centroid(const std::vector<Kernel::Point_3>& points) {
double x = 0.0, y = 0.0, z = 0.0;
for (const Kernel::Point_3& p : points) {
x += p.x();
y += p.y();
z += p.z();
}
size_t n = points.size();
return Kernel::Point_3(x / n, y / n, z / n);
}
Kernel::Plane_3 fit_plane(std::vector<Kernel::Point_3>& points, Kernel::Point_3& centroid)
{
double x0x0 = 0, x0y1 = 0, x0z2 = 0, x0_3 = 0;
double x1y0 = 0, y1y1 = 0, y1z2 = 0, y1_3 = 0;
double x2z0 = 0, y2z1 = 0, z2z2 = 0, z2_3 = 0;
double x3_0 = 0, y3_1 = 0, z3_2 = 0, n_3_3 = 0;
for (auto&& point : points) {
x0x0 += point.x() * point.x(
CGAL散乱点拟合最小二乘平面(3D平面拟合,基于Eigen)
于 2024-10-07 16:48:30 首次发布