# Synopsis

int mth_LeastSquaresLine2D(long option, double *pts, long n, int nc, double eps, double *p, double *pv)

# Purpose

Compute the least squares line thru a set of 2D points.

# Description

This routine creates a line which fits a set of data points in the least squares sense. The data is considered 2D (xy-plane), but the points array may have 2 or 3 coordinates per point (z-coordinate is ignored). This method does not consider orientation (direction) of the line. Furthermore, no correspondence between the data points and the extent of (p,pv) should be assumed. This routine uses formulas from R. A. Liming's book: Mathematics for Computer Graphics Aero Publishers, Inc. ; Fallbrook, CA ; 1979

# Input

## option

### MTH_PTVEC

Option giving form of line definition (pv). If option is set, the line is computed in point/vector form (pv is a vector). Otherwise, the line is in 2 point form (pv is a point).

## pts

The data points. The i-th point is located at pts[i*nc], where i=0,...,n-1.

## n

The number of points in pts.

## nc

The number of coordinates per point (nc=2 or 3, but the z-coord will not be used).

## eps

Zero length tolerance for 2D points.

# Output

## p

Point on the line (2D).

## pv

Point on the line or vector direction (see option). pv is 2D.

# Return

          = 0 : Line computed
          = 1 : No line computed
          .fi