CGAL::linear_least_squares_fitting_2

Definition

The function linear_least_squares_fitting_2 computes the best fitting 2D line of a 2D point set. The best fit line minimizes the sum of squared distances from the points to their projections onto the line.

#include <CGAL/linear_least_squares_fitting_2.h>

template < typename InputIterator, typename K>
typename K::FT
linear_least_squares_fitting_2 ( InputIterator first,
InputIterator beyond,
typename K::Line_2 & line,
typename K::Point_2 & centroid,
K k)
computes the best fitting 2D line of a 2D point set in the range [first,beyond). The value returned is a fitting quality between 0 and 1, where 0 means that the variance is the same along any line (a horizontal line going through the centroid is output by default), and 1 means that the variance is null orthogonally to the best fitting line.

The class K is the kernel in which the type InputIterator::value_type is defined. It can be omitted and deduced automatically from the value type.

Requirements

  1. InputIterator::value_type is equivalent to K::Point_2.
  2. line is the best fitting line computed.
  3. centroid is the centroid computed. This parameter can be omitted.