Last active
January 12, 2018 14:40
-
-
Save hugoledoux/f763636492dc72fb9f3fb77932b84c56 to your computer and use it in GitHub Desktop.
cgal-eigen-fitting-to2d
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
#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; | |
void cropz(); | |
int main(void) | |
{ | |
std::vector< Point3 > lsPts; | |
Point3 a(758731.86, 379196.97, 205.54); | |
Point3 b(758736.08, 379207.34, 205.54); | |
Point3 c(758743.72, 379204.23, 205.54); | |
Point3 d(758739.37, 379193.92, 205.54); | |
Point3 e(758732.25, 379196.81, 205.54); | |
lsPts.push_back(a); | |
lsPts.push_back(b); | |
lsPts.push_back(c); | |
lsPts.push_back(d); | |
lsPts.push_back(e); | |
//-- 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; | |
} | |
std::cout << "Projection of points to the plane:" << std::endl; | |
for (auto& p : lsPts) { | |
K::Point_2 pt = plane.to_2d(p); | |
std::cout << pt << std::endl; | |
} | |
std::cout << "============================" << std::endl; | |
cropz(); | |
return 0; | |
} | |
void cropz() { | |
std::vector< Point3 > lsPts; | |
Point3 a(758731.86, 379196.97, 5.54); | |
Point3 b(758736.08, 379207.34, 5.54); | |
Point3 c(758743.72, 379204.23, 5.54); | |
Point3 d(758739.37, 379193.92, 5.54); | |
Point3 e(758732.25, 379196.81, 5.54); | |
lsPts.push_back(a); | |
lsPts.push_back(b); | |
lsPts.push_back(c); | |
lsPts.push_back(d); | |
lsPts.push_back(e); | |
//-- 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; | |
} | |
std::cout << "Projection of points to the plane:" << std::endl; | |
for (auto& p : lsPts) { | |
K::Point_2 pt = plane.to_2d(p); | |
std::cout << pt << std::endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment