Created
December 11, 2017 14:25
-
-
Save hugoledoux/08bde5bf82a5aef7398b5a8d53b2c61b to your computer and use it in GitHub Desktop.
bug with linear_least_squares_fitting_3()?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example program for the linear_least_square_fitting function | |
// on a set of 3D triangles | |
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> | |
#include <CGAL/linear_least_squares_fitting_3.h> | |
#include <vector> | |
#include <math.h> | |
typedef CGAL::Exact_predicates_inexact_constructions_kernel K; | |
typedef K::Plane_3 Plane; | |
typedef K::Point_3 Point3; | |
int main(void) | |
{ | |
std::vector< Point3 > lsPts; | |
Point3 a(318.60, 919.16, 211.76); | |
Point3 b(317.60, 915.36, 208.79); | |
Point3 c(456.88, 878.84, 208.65); | |
Point3 d(458.14, 878.52, 208.65); | |
Point3 e(459.11, 882.25, 211.58); | |
lsPts.push_back(a); | |
lsPts.push_back(b); | |
lsPts.push_back(c); | |
lsPts.push_back(d); | |
lsPts.push_back(e); | |
std::cout << "collinear= " << CGAL::collinear(a, b, c) << std::endl; | |
//-- 1. plane thru first 3 points | |
Plane p1(a, b, c); | |
// std::cout << std::fixed << std::setprecision(3); | |
// std::cout << a << std::endl; | |
std::cout << "plane= " << p1 << std::endl; | |
for (auto& pt : lsPts) { | |
double dist = CGAL::squared_distance(pt, p1); | |
std::cout << "dist= " << sqrt(dist) << std::endl; | |
} | |
//-- 2. least-square plane | |
Plane plane; | |
linear_least_squares_fitting_3(lsPts.begin(), lsPts.end(), plane, CGAL::Dimension_tag<0>()); | |
std::cout << "lq-plane= " << plane << std::endl; | |
for (auto& pt : lsPts) { | |
double dist = CGAL::squared_distance(pt, plane); | |
std::cout << "dist= " << sqrt(dist) << std::endl; | |
} | |
//-- 3. least-square plane with only 3 points | |
linear_least_squares_fitting_3(lsPts.begin(), lsPts.begin()+3, plane, CGAL::Dimension_tag<0>()); | |
std::cout << "lq-plane-3-pts= " << plane << std::endl; | |
for (auto& pt : lsPts) { | |
double dist = CGAL::squared_distance(pt, plane); | |
std::cout << "dist= " << sqrt(dist) << std::endl; | |
} | |
std::cout << "==========" << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment